forked from apache/incubator-samoa
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
276 additions
and
16 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
samoa-api/src/main/java/org/apache/samoa/learners/InputInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.apache.samoa.learners; | ||
|
||
/* | ||
* #%L | ||
* SAMOA | ||
* %% | ||
* Copyright (C) 2014 - 2016 Apache Software Foundation | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.apache.samoa.instances.Instance; | ||
|
||
import java.io.Serializable; | ||
|
||
public interface InputInstance extends Serializable { | ||
Instance getInstance(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
samoa-api/src/main/java/org/apache/samoa/learners/classifiers/NominalInputInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.apache.samoa.learners.classifiers; | ||
|
||
/* | ||
* #%L | ||
* SAMOA | ||
* %% | ||
* Copyright (C) 2014 - 2016 Apache Software Foundation | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.apache.samoa.instances.*; | ||
import org.apache.samoa.learners.InputInstance; | ||
import org.apache.samoa.moa.core.FastVector; | ||
|
||
public class NominalInputInstance implements InputInstance { | ||
|
||
private int numNominals; | ||
private int numClasses; | ||
private double trueClass; // index started from 0 | ||
private int[] numValsPerNominal; | ||
private double[] data; // index started from 0 | ||
|
||
public NominalInputInstance(int numNominals, int numClasses, double trueClass, | ||
int[] numValsPerNominal, double[] data) { | ||
this.numNominals = numNominals; | ||
this.numClasses = numClasses; | ||
this.trueClass = trueClass; | ||
this.numValsPerNominal = numValsPerNominal; | ||
this.data = data; | ||
} | ||
|
||
private InstancesHeader generateHeader() { | ||
FastVector<Attribute> attributes = new FastVector<>(); | ||
|
||
for (int i = 0; i < this.numNominals; i++) { | ||
FastVector<String> nominalAttVals = new FastVector<>(); | ||
for (int j = 0; j < this.numValsPerNominal[i]; j++) { | ||
nominalAttVals.addElement("value" + (j + 1)); | ||
} | ||
attributes.addElement(new Attribute("nominal" + (i + 1), | ||
nominalAttVals)); | ||
} | ||
|
||
FastVector<String> classLabels = new FastVector<>(); | ||
for (int i = 0; i < this.numClasses; i++) { | ||
classLabels.addElement("class" + (i + 1)); | ||
} | ||
attributes.addElement(new Attribute("class", classLabels)); | ||
|
||
InstancesHeader instancesHeader = new InstancesHeader( | ||
new Instances(null, attributes, 0)); | ||
instancesHeader.setClassIndex(instancesHeader.numAttributes() - 1); | ||
|
||
return instancesHeader; | ||
} | ||
|
||
@Override | ||
public Instance getInstance() { | ||
InstancesHeader header = this.generateHeader(); | ||
Instance inst = new DenseInstance(header.numAttributes()); | ||
|
||
for (int i = 0; i < this.numNominals; i++) { | ||
inst.setValue(i, this.data[i]); | ||
} | ||
|
||
inst.setDataset(header); | ||
inst.setClassValue(this.trueClass); | ||
|
||
return inst; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
samoa-api/src/main/java/org/apache/samoa/learners/classifiers/NumericInputInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.apache.samoa.learners.classifiers; | ||
|
||
/* | ||
* #%L | ||
* SAMOA | ||
* %% | ||
* Copyright (C) 2014 - 2016 Apache Software Foundation | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.apache.samoa.instances.*; | ||
import org.apache.samoa.learners.InputInstance; | ||
import org.apache.samoa.moa.core.FastVector; | ||
|
||
public class NumericInputInstance implements InputInstance { | ||
private int numNumerics; | ||
private int numClasses; | ||
private double trueClass; // index started from 0 | ||
private double[] data; | ||
|
||
public NumericInputInstance(int numNumerics, int numClasses, double trueClass, double[] data) { | ||
this.numNumerics = numNumerics; | ||
this.numClasses = numClasses; | ||
this.trueClass = trueClass; | ||
this.data = data; | ||
} | ||
|
||
private InstancesHeader generateHeader() { | ||
FastVector<Attribute> attributes = new FastVector<>(); | ||
|
||
for (int i = 0; i < this.numNumerics; i++) { | ||
attributes.addElement(new Attribute("numeric" + (i + 1))); | ||
} | ||
|
||
FastVector<String> classLabels = new FastVector<>(); | ||
for (int i = 0; i < this.numClasses; i++) { | ||
classLabels.addElement("class" + (i + 1)); | ||
} | ||
attributes.addElement(new Attribute("class", classLabels)); | ||
|
||
InstancesHeader instancesHeader = new InstancesHeader( | ||
new Instances(null, attributes, 0)); | ||
instancesHeader.setClassIndex(instancesHeader.numAttributes() - 1); | ||
|
||
return instancesHeader; | ||
} | ||
|
||
@Override | ||
public Instance getInstance() { | ||
InstancesHeader header = this.generateHeader(); | ||
Instance inst = new DenseInstance(header.numAttributes()); | ||
|
||
for (int i = 0; i < this.numNumerics; i++) { | ||
inst.setValue(i, this.data[i]); | ||
} | ||
|
||
inst.setDataset(header); | ||
inst.setClassValue(this.trueClass); | ||
|
||
return inst; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
samoa-api/src/main/java/org/apache/samoa/learners/clusterers/ClusterInputInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.apache.samoa.learners.clusterers; | ||
|
||
/* | ||
* #%L | ||
* SAMOA | ||
* %% | ||
* Copyright (C) 2014 - 2016 Apache Software Foundation | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.apache.samoa.instances.*; | ||
import org.apache.samoa.learners.InputInstance; | ||
import org.apache.samoa.moa.core.DataPoint; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ClusterInputInstance implements InputInstance { | ||
private int numAtts; | ||
private int timeStamp; | ||
private double[] data; | ||
|
||
public ClusterInputInstance(int numAtts, int timeStamp, double[] data) { | ||
this.numAtts = numAtts; | ||
this.timeStamp = timeStamp; | ||
this.data = data; | ||
} | ||
|
||
private InstancesHeader generateHeader() { | ||
ArrayList<Attribute> attributes = new ArrayList<>(); | ||
|
||
for (int i = 0; i < this.numAtts; i++) { | ||
attributes.add(new Attribute("att" + (i + 1))); | ||
} | ||
|
||
// attributes.add(new Attribute("class", null)); | ||
|
||
InstancesHeader instancesHeader = new InstancesHeader( | ||
new Instances(null, attributes, 0)); | ||
instancesHeader.setClassIndex(instancesHeader.numAttributes() - 1); | ||
|
||
return instancesHeader; | ||
} | ||
|
||
@Override | ||
public Instance getInstance() { | ||
Instance inst = new DenseInstance(1.0, this.data); | ||
inst.setDataset(generateHeader()); | ||
return new DataPoint(inst, this.timeStamp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters