Skip to content
Snippets Groups Projects
Commit e7013e72 authored by BBQ's avatar BBQ
Browse files

fix activity inputs

parent 084d02df
No related branches found
No related tags found
1 merge request!19dev to master
...@@ -18,7 +18,7 @@ String Item: id="w_accel_y" label="" state="4.9320555" topic="w_accel_y"; ...@@ -18,7 +18,7 @@ String Item: id="w_accel_y" label="" state="4.9320555" topic="w_accel_y";
String Item: id="w_accel_z" label="" state="8.145074" topic="w_accel_z"; String Item: id="w_accel_z" label="" state="8.145074" topic="w_accel_z";
String Item: id="w_rotation_x" label="" state="0.2374878" topic="w_rotation_x"; String Item: id="w_rotation_x" label="" state="0.2374878" topic="w_rotation_x";
String Item: id="w_rotation_y" label="" state="-0.032836914" topic="w_rotation_y"; String Item: id="w_rotation_y" label="" state="-0.032836914" topic="w_rotation_y";
String Item: id="w_rotation_z" label="" state="0.3381958" topic="w_rotation_y"; String Item: id="w_rotation_z" label="" state="0.3381958" topic="w_rotation_z";
String Item: id="w_brightness" label="" state="bright" topic="w_brightness"; String Item: id="w_brightness" label="" state="bright" topic="w_brightness";
//String Item: id="activity" label="" state="lying" topic="activity"; //String Item: id="activity" label="" state="lying" topic="activity";
Activity Item: id="activity" topic="activity"; Activity Item: id="activity" topic="activity";
......
...@@ -25,6 +25,12 @@ public class MachineLearningImpl implements MachineLearningDecoder, MachineLearn ...@@ -25,6 +25,12 @@ public class MachineLearningImpl implements MachineLearningDecoder, MachineLearn
private List<Item> relevant_item_list; private List<Item> relevant_item_list;
private String[] preference_result; private String[] preference_result;
private String[] a_new_data = new String[12];
private String[] p_new_data = new String[2];
private int a_length = 0;
boolean empty;
private Root root; private Root root;
private String activity_result; private String activity_result;
...@@ -98,36 +104,52 @@ public class MachineLearningImpl implements MachineLearningDecoder, MachineLearn ...@@ -98,36 +104,52 @@ public class MachineLearningImpl implements MachineLearningDecoder, MachineLearn
or let knowledge base pass all relevant items <- push model or let knowledge base pass all relevant items <- push model
*/ */
if (this.goal == GOAL_ACTIVITY_PHONE_AND_WATCH) { if (this.goal == GOAL_ACTIVITY_PHONE_AND_WATCH) {
String[] new_data = new String[12];
for (int i = 0; i < new_data.length; i++) {
new_data[i] = "0";
}
for (Item item : changedItems) { for (Item item : changedItems) {
if(item.getID().equals("m_accel_x"))
{
a_length = 0;
}
int i = 0; int i = 0;
for (Item item1 : relevant_item_list) { for (Item item1 : relevant_item_list) {
if (item.getTopic().toString().equals(item1.getTopic().toString())) { if (item.getTopic().toString().equals(item1.getTopic().toString())) {
new_data[i] = item.getStateAsString(); this.a_new_data[i] = item.getStateAsString();
} }
i++; i++;
} }
a_length++;
}
if(a_length == 12){
for (String value : a_new_data){
if(value == null){
empty = true;
}
}
if(!empty){
this.activity_result = learner.activity_predictor(a_new_data);
}
a_length = 0;
for (int j=0; j < this.a_new_data.length; j++){
this.a_new_data[j] = null;
}
} }
this.activity_result = learner.activity_predictor(new_data);
} else if (this.goal == GOAL_PREFERENCE_BRIGHTNESS_IRIS) { } else if (this.goal == GOAL_PREFERENCE_BRIGHTNESS_IRIS) {
String[] new_data = new String[2];
for (Item item : changedItems) { for (Item item : changedItems) {
if (root.getSmartHomeEntityModel().getActivityItem().equals(item)) { if (root.getSmartHomeEntityModel().getActivityItem().equals(item)) {
String test = item.getStateAsString(); String test = item.getStateAsString();
int index = Math.round(Float.valueOf(test)); int index = Math.round(Float.valueOf(test));
new_data[0] = root.getMachineLearningRoot().getActivity(index).getLabel(); this.p_new_data[0] = root.getMachineLearningRoot().getActivity(index).getLabel();
} }
if (item.getID().equals("w_brightness")) { if (item.getID().equals("w_brightness")) {
new_data[1] = item.getStateAsString(); this.p_new_data[1] = item.getStateAsString();
} }
} }
this.preference_result = learner.preference_predictor(new_data); logger.info("debug_preference_new_data");
logger.info(Arrays.toString(this.p_new_data));
this.preference_result = learner.preference_predictor(this.p_new_data);
logger.info("debug for p"); logger.info("debug for p");
logger.info(Arrays.toString(preference_result)); logger.info(Arrays.toString(this.preference_result));
} }
} }
......
...@@ -124,10 +124,10 @@ public class Main { ...@@ -124,10 +124,10 @@ public class Main {
//System.out.println("perference is: "+ result[1]);**/ //System.out.println("perference is: "+ result[1]);**/
} }
public static void activity_validation_learner(){ public static void activity_validation_learner(){
ReadCSV csv = new ReadCSV("datasets/backup/activity_data.csv", true, CSVFormat.DECIMAL_POINT); ReadCSV csv = new ReadCSV("../datasets/backup/activity_data.csv", true, CSVFormat.DECIMAL_POINT);
String[] line = new String[11]; String[] line = new String[11];
Learner learner = new Learner(); Learner learner = new Learner();
learner.train("datasets/backup/activity_data.csv","datasets/backup/preference_data.csv"); learner.train("../datasets/backup/activity_data.csv","../datasets/backup/preference_data.csv");
int wrong=0; int wrong=0;
int right=0; int right=0;
int i =0; int i =0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment