This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 594
first checkin for heron ml #2978
Open
skanjila
wants to merge
2
commits into
apache:master
Choose a base branch
from
skanjila:mlefforts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
heron/mlmgr/src/main/java/org/apache/heron/LocalStormDoTask.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,82 @@ | ||
package org.apache.heron; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.samoa.topology.impl.StormSamoaUtils; | ||
import org.apache.samoa.topology.impl.StormTopology; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.apache.commons.configuration.Configuration; | ||
|
||
import backtype.storm.Config; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||
import backtype.storm.utils.Utils; | ||
|
||
/** | ||
* The main class to execute a SAMOA task in LOCAL mode in Storm. | ||
* | ||
* @author Arinto Murdopo | ||
* | ||
*/ | ||
public class LocalStormDoTask { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LocalStormDoTask.class); | ||
private static final String EXECUTION_DURATION_KEY ="samoa.storm.local.mode.execution.duration"; | ||
private static final String SAMOA_STORM_PROPERTY_FILE_LOC ="samoa-storm.properties"; | ||
/** | ||
* The main method. | ||
* | ||
* @param args | ||
* the arguments | ||
*/ | ||
public static void main(String[] args) { | ||
|
||
List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args)); | ||
|
||
int numWorker = StormSamoaUtils.numWorkers(tmpArgs); | ||
|
||
args = tmpArgs.toArray(new String[0]); | ||
|
||
// convert the arguments into Storm topology | ||
StormTopology stormTopo = StormSamoaUtils.argsToTopology(args); | ||
String topologyName = stormTopo.getTopologyName(); | ||
|
||
Config conf = new Config(); | ||
// conf.putAll(Utils.readStormConfig()); | ||
conf.setDebug(false); | ||
|
||
// local mode | ||
conf.setMaxTaskParallelism(numWorker); | ||
|
||
backtype.storm.LocalCluster cluster = new backtype.storm.LocalCluster(); | ||
cluster.submitTopology(topologyName, conf, stormTopo.getStormBuilder().createTopology()); | ||
|
||
// Read local mode execution duration from property file | ||
Configuration stormConfig = StormSamoaUtils.getPropertyConfig(LocalStormDoTask.SAMOA_STORM_PROPERTY_FILE_LOC); | ||
long executionDuration= stormConfig.getLong(LocalStormDoTask.EXECUTION_DURATION_KEY); | ||
backtype.storm.utils.Utils.sleep(executionDuration * 1000); | ||
|
||
cluster.killTopology(topologyName); | ||
cluster.shutdown(); | ||
|
||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
heron/mlmgr/src/main/java/org/apache/heron/learners/AdaptiveLearner.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,46 @@ | ||
package org.apache.heron.learners; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
import org.apache.samoa.moa.classifiers.core.driftdetection.ChangeDetector; | ||
|
||
/** | ||
* The Interface Adaptive Learner. Initializing Classifier should initalize PI to connect the Classifier with the input | ||
* stream and initialize result stream so that other PI can connect to the classification result of this classifier | ||
*/ | ||
|
||
public interface AdaptiveLearner extends Learner{ | ||
|
||
/** | ||
* Gets the change detector item. | ||
* | ||
* @return the change detector item | ||
*/ | ||
public ChangeDetector getChangeDetector(); | ||
|
||
/** | ||
* Sets the change detector item. | ||
* | ||
* @param cd | ||
* the change detector item | ||
*/ | ||
public void setChangeDetector(ChangeDetector cd); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
heron/mlmgr/src/main/java/org/apache/heron/learners/ClassificationLearner.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,26 @@ | ||
package org.apache.heron.learners; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
import org.apache.samoa.learners.Learner; | ||
|
||
public interface ClassificationLearner extends Learner { | ||
|
||
} |
202 changes: 202 additions & 0 deletions
202
heron/mlmgr/src/main/java/org/apache/heron/learners/InstanceContent.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,202 @@ | ||
package org.apache.heron.learners; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
/** | ||
* License | ||
*/ | ||
|
||
import net.jcip.annotations.Immutable; | ||
|
||
import org.apache.samoa.core.SerializableInstance; | ||
import org.apache.samoa.instances.Instance; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* The Class InstanceContent. | ||
*/ | ||
@Immutable | ||
final public class InstanceContent implements Serializable { | ||
|
||
private static final long serialVersionUID = -8620668863064613841L; | ||
|
||
private long instanceIndex; | ||
private int classifierIndex; | ||
private int evaluationIndex; | ||
private SerializableInstance instance; | ||
private boolean isTraining; | ||
private boolean isTesting; | ||
private boolean isLast = false; | ||
|
||
public InstanceContent() { | ||
|
||
} | ||
|
||
/** | ||
* Instantiates a new instance event. | ||
* | ||
* @param index | ||
* the index | ||
* @param instance | ||
* the instance | ||
* @param isTraining | ||
* the is training | ||
*/ | ||
public InstanceContent(long index, Instance instance, | ||
boolean isTraining, boolean isTesting) { | ||
if (instance != null) { | ||
this.instance = new SerializableInstance(instance); | ||
} | ||
this.instanceIndex = index; | ||
this.isTraining = isTraining; | ||
this.isTesting = isTesting; | ||
} | ||
|
||
/** | ||
* Gets the single instance of InstanceEvent. | ||
* | ||
* @return the instance. | ||
*/ | ||
public Instance getInstance() { | ||
return instance; | ||
} | ||
|
||
/** | ||
* Gets the instance index. | ||
* | ||
* @return the index of the data vector. | ||
*/ | ||
public long getInstanceIndex() { | ||
return instanceIndex; | ||
} | ||
|
||
/** | ||
* Gets the class id. | ||
* | ||
* @return the true class of the vector. | ||
*/ | ||
public int getClassId() { | ||
// return classId; | ||
return (int) instance.classValue(); | ||
} | ||
|
||
/** | ||
* Checks if is training. | ||
* | ||
* @return true if this is training data. | ||
*/ | ||
public boolean isTraining() { | ||
return isTraining; | ||
} | ||
|
||
/** | ||
* Set training flag. | ||
* | ||
* @param training | ||
* flag. | ||
*/ | ||
public void setTraining(boolean training) { | ||
this.isTraining = training; | ||
} | ||
|
||
/** | ||
* Checks if is testing. | ||
* | ||
* @return true if this is testing data. | ||
*/ | ||
public boolean isTesting() { | ||
return isTesting; | ||
} | ||
|
||
/** | ||
* Set testing flag. | ||
* | ||
* @param testing | ||
* flag. | ||
*/ | ||
public void setTesting(boolean testing) { | ||
this.isTesting = testing; | ||
} | ||
|
||
/** | ||
* Gets the classifier index. | ||
* | ||
* @return the classifier index | ||
*/ | ||
public int getClassifierIndex() { | ||
return classifierIndex; | ||
} | ||
|
||
/** | ||
* Sets the classifier index. | ||
* | ||
* @param classifierIndex | ||
* the new classifier index | ||
*/ | ||
public void setClassifierIndex(int classifierIndex) { | ||
this.classifierIndex = classifierIndex; | ||
} | ||
|
||
/** | ||
* Gets the evaluation index. | ||
* | ||
* @return the evaluation index | ||
*/ | ||
public int getEvaluationIndex() { | ||
return evaluationIndex; | ||
} | ||
|
||
/** | ||
* Sets the evaluation index. | ||
* | ||
* @param evaluationIndex | ||
* the new evaluation index | ||
*/ | ||
public void setEvaluationIndex(int evaluationIndex) { | ||
this.evaluationIndex = evaluationIndex; | ||
} | ||
|
||
/** | ||
* Sets the instance index. | ||
* | ||
* @param instanceIndex | ||
* the new evaluation index | ||
*/ | ||
public void setInstanceIndex(long instanceIndex) { | ||
this.instanceIndex = instanceIndex; | ||
} | ||
|
||
public boolean isLastEvent() { | ||
return isLast; | ||
} | ||
|
||
public void setLast(boolean isLast) { | ||
this.isLast = isLast; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String | ||
.format( | ||
"InstanceContent [instanceIndex=%s, classifierIndex=%s, evaluationIndex=%s, instance=%s, isTraining=%s, isTesting=%s, isLast=%s]", | ||
instanceIndex, classifierIndex, evaluationIndex, instance, isTraining, isTesting, isLast); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the package path should be
org.apache.heron.ml
if it's a general class needed by all machine learning runtime. If it's specific for samoa, then the package path should beorg.apache.heron.ml.samoa
.And this also applies to all the following files.