Skip to content
Snippets Groups Projects
Commit d644869f authored by boqiren's avatar boqiren
Browse files

add ML Interface

parent 6b27cf31
No related branches found
No related tags found
No related merge requests found
package de.tudresden.inf.st.eraser.feedbackloop.learner_backup; package de.tudresden.inf.st.eraser.feedbackloop.learner_backup;
public class MachineLearningDecoder { import de.tudresden.inf.st.eraser.jastadd.model.MachineLearningResult;
import java.time.Instant;
public interface MachineLearningDecoder {
/**
* Execute the machine learning model and returns the classification result.
* @return the result of the classification
*/
MachineLearningResult classify();
// less important
/**
* Returns the time when the model was last updated, i.e., when the last training was completed.
* @return the time when the model was last updated, or <code>null</code> if the model was not trained yet
*/
Instant lastModelUpdate();
} }
package de.tudresden.inf.st.eraser.feedbackloop.learner_backup; package de.tudresden.inf.st.eraser.feedbackloop.learner_backup;
import de.tudresden.inf.st.eraser.jastadd.model.Item;
import de.tudresden.inf.st.eraser.jastadd.model.Root;
import java.util.List;
public interface MachineLearningEncoder { public interface MachineLearningEncoder {
/**
* Update when new data is available.
* @param model The underlying model
* @param changedItems A list of items whose state has changed
*/
void newData(Root model, List<Item> changedItems);
// to be discussed, in which form this is specified
/**
* Get the items that this model is supposed to change.
* @return the list of targeted items
*/
List<Item> getTargets(Root model);
// to be discussed, in which form this is specified
/**
* Get the items which are relevant for the decision making of this model.
* @return the list of items relevant for decision making
*/
List<Item> getRelevantItems(Root model);
// to be discussed, if this is necessary
/**
* Explicit hint for this model to start/trigger training. The model might ignore this hint.
*/
void triggerTraining();
} }
...@@ -4,20 +4,32 @@ import de.tudresden.inf.st.eraser.jastadd.model.*; ...@@ -4,20 +4,32 @@ import de.tudresden.inf.st.eraser.jastadd.model.*;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
public class MachineLearningEncoderImpl implements MachineLearningEncoder, MachineLearningDecoder { public class MachineLearningEncoderImpl implements MachineLearningDecoder,MachineLearningEncoder {
private String[] new_data = new String[13];
private List<Item> target_item_list;
private List<Item> relevant_item_list;
private String[] result;
String[] new_data = new String[13];
List<Item> target_item_list;
List<Item> relevant_item_list;
@Override @Override
public void newData(Root model, List<Item> changedItems) { public void newData(Root model, List<Item> changedItems) {
String topic = changedItems.get(0).getTopic().toString(); /**String topic = changedItems.get(0).getTopic().toString();
if(topic.equals("oh2/samsung/items1")){ if(topic.equals("oh2/samsung/items1")){
new_data[0]=changedItems.get(0).influxMeasurementName(); new_data[0]=changedItems.get(0).influxMeasurementName();
} }
model.getOpenHAB2Model().items(); model.getOpenHAB2Model().items();
Item iris_item=model.getOpenHAB2Model().resolveItem("iris_item").get(); Item iris_item=model.getOpenHAB2Model().resolveItem("iris_item").get();
iris_item.getStateAsString(); iris_item.getStateAsString();*/
int i=0;
for (Item item: changedItems){
if(i<13) {
new_data[i] = item.getStateAsString();
i++;
}
}
Learner learner= new Learner();
result = learner.predictor(new_data);
} }
@Override @Override
...@@ -61,8 +73,6 @@ public class MachineLearningEncoderImpl implements MachineLearningEncoder, Machi ...@@ -61,8 +73,6 @@ public class MachineLearningEncoderImpl implements MachineLearningEncoder, Machi
relevant_item_list.add(w_rotation_y); relevant_item_list.add(w_rotation_y);
relevant_item_list.add(w_rotation_z); relevant_item_list.add(w_rotation_z);
relevant_item_list.add(w_brightness); relevant_item_list.add(w_brightness);
return null; return null;
} }
...@@ -79,6 +89,8 @@ public class MachineLearningEncoderImpl implements MachineLearningEncoder, Machi ...@@ -79,6 +89,8 @@ public class MachineLearningEncoderImpl implements MachineLearningEncoder, Machi
@Override @Override
public MachineLearningResult classify() { public MachineLearningResult classify() {
String activity=result[0];
String[] preference= {result[1],result[2]};
return null; return null;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment