Permalink
Browse files

renaming

  • Loading branch information...
esk committed May 27, 2012
1 parent 09cbee3 commit db54f9c655f76d825e0049dd06eaa9972cfa61c6
@@ -4,18 +4,18 @@
import norsys.netica.NeticaException;
import norsys.neticaEx.aliases.Node;
public class SensorReading extends Node {
public class SensorNode extends Node {
public static final int RADIATION = 0;
public static final int TEMPERATURE = 0;
private CompartmentProperties properties;
private int sensorType;
public SensorReading() throws NeticaException {
public SensorNode() throws NeticaException {
super();
}
public SensorReading(CompartmentProperties properties, String name,
public SensorNode(CompartmentProperties properties, String name,
int state, Net net, int sensorType) throws NeticaException {
super(name, state, net);
@@ -5,7 +5,7 @@
import java.util.Map;
import no.uia.ikt411.ap.domain.CompartmentProperties;
import no.uia.ikt411.ap.domain.SensorReading;
import no.uia.ikt411.ap.domain.SensorNode;
import no.uia.ikt411.ap.math.MathController;
import no.uia.ikt411.ap.math.Thermodynamics;
import norsys.netica.Net;
@@ -28,46 +28,31 @@
*/
// public static final double[] timeSeries = new double[] { 0, 1, 60, 125,
// 195, 345, 495, 645, 795, 945, 1095, 1295, 1800 };
public static final double[] timeSeries = new double[] { 0, 1, 30, 60, 90,
public static final double[] TIME_SERIES = new double[] { 0, 1, 30, 60, 90,
120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480,
510, 540, 570, 600, 630, 660, 690, 720, 750, 780, 810, 840, 870,
900, 930, 960, 990, 1020, 1050, 1080, 1210, 1240, 1270, 1300 };
/**
* in seconds
*/
public static final int TIME_STEP = 150;
// /**
// * in seconds
// */
// public static final int TIME_STEP = 150;
//
/**
* in seconds
*/
public static final int SIMULATION_TIME = 1800;
// public final static double[] temperatureDistribution = new double[] { 0,
// 0,
// 0, 60, 60, 60, 60, 60, 120, 120, 120, 120, 180, 180, 180, 180, 180,
// 240, 240, 240, 240, 300, 300, 300, 300, 360, 360, 360, 360, 420,
// 420, 420, 420, 480, 480, 480, 540, 540, 540, 600, 600, 600, 660,
// 660, 660, 720, 720, 720, 780, 780, 780, 840, 840, 900, 900, 960,
// 960, 1020, 1020, 1080, 1140, 1200 };
//
// public final static double[] radiationDistribution = new double[] { 0, 0,
// 0, 60, 60, 60, 60, 60, 120, 120, 120, 120, 180, 180, 180, 180, 180,
// 240, 240, 240, 240, 300, 300, 300, 300, 360, 360, 360, 360, 420,
// 420, 420, 420, 480, 480, 480, 540, 540, 540, 600, 600, 600, 660,
// 660, 660, 720, 720, 720, 780, 780, 780, 840, 840, 900, 900, 960,
// 960, 1020, 1020, 1080, 1140, 1200 };
// private double[] temperatureSeries = new double[] { 0, 60, 120, 180, 240,
// 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960, 1020,
// 1080, 1140, 1200 };
private double[] temperatureSeries = new double[] { 26, 30, 36, 47, 60, 70,
80, 90, 100, 110, 120, 160, 200, 260, 340, 420, 520, 630, 760, 890,
1160, 1350, 1500, 1700, 1900 };
public static final double[] TEMPERATURE_SERIES = new double[] { 26, 30,
36, 47, 60, 70, 80, 90, 100, 110, 120, 160, 200, 260, 340, 420,
520, 630, 760, 890, 1160, 1350, 1500, 1700, 1900 };
private double[] radiationSeries = new double[] { 0, 60, 120, 180, 240,
300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960, 1020,
1080, 1140, 1200 };
// private double[] radiationSeries = new double[] { 0, 60, 120, 180, 240,
// 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960, 1020,
// 1080, 1140, 1200 };
public static int TEMPERATURE_INDEX = 0;
public static int RADIATION_INDEX = 1;
@@ -87,19 +72,11 @@ public BuildNet(Net net) throws NeticaException {
}
public void createBayesNet(ArrayList<SensorReading[]> sensorReadings,
public void createBayesNet(ArrayList<SensorNode[]> sensorReadings,
Map<Integer, CompartmentProperties> compartmentProperties)
throws NeticaException {
// NodeList parents = sensorReadings.get(0)[0].getParents();
// for (int i = 0; i < parents.size(); i++) {
// CompartmentNode compNode = (CompartmentNode) parents.elementAt(i);
// if (compNode.getProperties().getId() != sensorReadings.get(0)[0]
// .getProperties().getId())
// compNode.delete();
// }
for (SensorReading[] sensorReading : sensorReadings) {
for (SensorNode[] sensorReading : sensorReadings) {
System.out.println(sensorReading[0].getName());
fillTable(sensorReading, compartmentProperties,
@@ -112,26 +89,23 @@ public void createBayesNet(ArrayList<SensorReading[]> sensorReadings,
NodeList nodes = net.getNodes();
if (nodes.size() < 16) {
System.out.println("Saving...");
Streamer stream = new Streamer(
"/home/enok/Dropbox/school/ikt411/results/netica/net-"
+ System.currentTimeMillis() + ".dne");
Streamer stream = new Streamer("results/net-"
+ System.currentTimeMillis() + ".dne");
net.write(stream);
System.out.println("Finished Saving");
} else {
System.out.println("Could not save");
}
// writeTestResultsToFile(testPicker);
}
private static int counter = 0;
private void fillTable(SensorReading[] sensorReading,
private void fillTable(SensorNode[] sensorReading,
Map<Integer, CompartmentProperties> compartmentProperties,
Thermodynamics thermoDynamics) throws NeticaException {
int parentCount = sensorReading[0].getParents().size();
int stateCount = timeSeries.length - 1;
int stateCount = TIME_SERIES.length - 1;
int permutationIndex = 0;
int permutationCount = (int) Math.pow(stateCount, parentCount);
@@ -176,7 +150,7 @@ private void fillTable(SensorReading[] sensorReading,
first = false;
}
private void addTemperature(SensorReading[] sensorReading,
private void addTemperature(SensorNode[] sensorReading,
Map<Integer, CompartmentProperties> compartmentProperties,
Thermodynamics thermoDynamics, int[] permutation)
throws NeticaException {
@@ -193,11 +167,7 @@ private void addTemperature(SensorReading[] sensorReading,
sensorReading[TEMPERATURE_INDEX].setRealFuncTable(permutation,
radiationAndTemperature[TEMPERATURE_INDEX]);
// if (false) {
// sensorReading[RADIATION_INDEX].setRealFuncTable(
// permutation,
// radiationAndTemperature[RADIATION_INDEX]);
// }
} catch (Exception e) {
String tt = "";
for (int p : permutation) {
@@ -252,42 +222,8 @@ private void printTestValues(int[] permutation, Double sensedTemperature) {
}
// private void writeTestResultsToFile(
// Map<Integer[], ArrayList<Double>> testPicker2) {
//
// File file = new File("results/tests-at-" + System.currentTimeMillis());
// String data = "";
//
// for (Entry<Integer[], ArrayList<Double>> entry : testPicker2.entrySet())
// {
//
// Integer[] keys = entry.getKey();
// for (Integer key : keys) {
// data += "" + key + " ";
// }
// ArrayList<Double> arrayList = entry.getValue();
// for (Double d : arrayList) {
// data += "" + d + " ";
// }
// data += "\n";
// }
//
// try {
// FileUtils.writeStringToFile(file, data, "utf-8");
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// public double[] getTimeSeries() {
// return timeSeries;
// }
public double[] getTemperatureSeries() {
return temperatureSeries;
return TEMPERATURE_SERIES;
}
public double[] getRadiationSeries() {
return radiationSeries;
}
}
@@ -9,7 +9,7 @@
import no.uia.ikt411.ap.domain.CompartmentNode;
import no.uia.ikt411.ap.domain.CompartmentProperties;
import no.uia.ikt411.ap.domain.SensorReading;
import no.uia.ikt411.ap.domain.SensorNode;
import no.uia.ikt411.ap.domain.Wall;
import norsys.netica.Environ;
import norsys.netica.Net;
@@ -55,7 +55,7 @@ public SensorSimulator() throws NeticaException {
private void sense(int[] ids) throws NeticaException {
long startTime = System.currentTimeMillis();
ArrayList<SensorReading[]> sensorReadings = getSensorReadings(ids);
ArrayList<SensorNode[]> sensorReadings = getSensorReadings(ids);
createAncestorNodes(sensorReadings);
@@ -92,11 +92,10 @@ private void sense(int[] ids) throws NeticaException {
System.out.println("Used " + endTime + " seconds");
}
private void removeSensorNodeByType(
ArrayList<SensorReading[]> sensorReadings, int sensorType)
throws NeticaException {
private void removeSensorNodeByType(ArrayList<SensorNode[]> sensorReadings,
int sensorType) throws NeticaException {
for (SensorReading[] sensorReading : sensorReadings) {
for (SensorNode[] sensorReading : sensorReadings) {
sensorReading[sensorType].delete();
}
@@ -197,9 +196,9 @@ private JFreeChart createBarChart(Node node) throws NeticaException {
return chart;
}
private void createAncestorNodes(ArrayList<SensorReading[]> sensorReadings)
private void createAncestorNodes(ArrayList<SensorNode[]> sensorReadings)
throws NeticaException {
for (SensorReading[] sensorReading : sensorReadings) {
for (SensorNode[] sensorReading : sensorReadings) {
CompartmentProperties sensorProperties = sensorReading[0]
.getProperties();
@@ -215,7 +214,7 @@ private void createAncestorNodes(ArrayList<SensorReading[]> sensorReadings)
selfCompartmentNode = new CompartmentNode(sensorProperties, "c"
+ sensorId, 0, net);
compartmentProperties.put(sensorId, sensorProperties);
selfCompartmentNode.setLevels(BuildNet.timeSeries);
selfCompartmentNode.setLevels(BuildNet.TIME_SERIES);
}
// selfCompartmentNode = new CompartmentNode(sensorProperties, "c"
// + sensorId, 0, net);
@@ -239,34 +238,34 @@ private void createAncestorNodes(ArrayList<SensorReading[]> sensorReadings)
net);
compartmentProperties.put(key, prop);
}
compartmentNode.setLevels(BuildNet.timeSeries);
compartmentNode.setLevels(BuildNet.TIME_SERIES);
sensorReading[0].addLink(compartmentNode);
sensorReading[1].addLink(compartmentNode);
}
}
}
private ArrayList<SensorReading[]> getSensorReadings(int[] ids)
private ArrayList<SensorNode[]> getSensorReadings(int[] ids)
throws NeticaException {
ArrayList<SensorReading[]> sensorReadings = new ArrayList<SensorReading[]>();
ArrayList<SensorNode[]> sensorReadings = new ArrayList<SensorNode[]>();
for (int id : ids) {
CompartmentProperties sensorCompartmentProperties = (CompartmentProperties) factory
.getBean("c" + id);
SensorReading radiationReading = new SensorReading(
SensorNode radiationReading = new SensorNode(
sensorCompartmentProperties, "S" + id + "R", 0, net,
SensorReading.RADIATION);
SensorNode.RADIATION);
SensorReading temperatureReading = new SensorReading(
SensorNode temperatureReading = new SensorNode(
sensorCompartmentProperties, "S" + id + "T", 0, net,
SensorReading.TEMPERATURE);
SensorNode.TEMPERATURE);
radiationReading.setLevels(buildNet.getRadiationSeries());
temperatureReading.setLevels(buildNet.getTemperatureSeries());
radiationReading.setLevels(BuildNet.TEMPERATURE_SERIES);
temperatureReading.setLevels(BuildNet.TEMPERATURE_SERIES);
sensorReadings.add(new SensorReading[] { temperatureReading,
sensorReadings.add(new SensorNode[] { temperatureReading,
radiationReading });
}
@@ -3,7 +3,7 @@
import java.util.Map;
import no.uia.ikt411.ap.domain.CompartmentProperties;
import no.uia.ikt411.ap.domain.SensorReading;
import no.uia.ikt411.ap.domain.SensorNode;
import no.uia.ikt411.ap.fire_detector.BuildNet;
import norsys.netica.NeticaException;
import norsys.netica.Node;
@@ -18,7 +18,7 @@ public MathController() {
}
public Double[] calculateRadiationAndTemperature(
SensorReading[] sensorReading, int[] ancestorDurations,
SensorNode[] sensorReading, int[] ancestorDurations,
Map<Integer, CompartmentProperties> compartmentProperties,
Thermodynamics thermoDynamics) throws NeticaException {
@@ -40,14 +40,13 @@ public MathController() {
parentIds[i] = Integer.parseInt(node.getName().substring(1));
}
// Map<Integer, Integer> ancestorTime = new HashMap<Integer, Integer>();
String functionCall = String.format("Temp[%f",
BuildNet.timeSeries[maxDuration]);
BuildNet.TIME_SERIES[maxDuration]);
for (int i = 0; i < parents.size(); i++) {
functionCall += String
.format(",%f",
((maxDuration - BuildNet.timeSeries[ancestorDurations[i]])));
((maxDuration - BuildNet.TIME_SERIES[ancestorDurations[i]])));
}
functionCall += "]-273.15";
@@ -77,10 +76,10 @@ public MathController() {
}
// printPermuatation(ancestorDurations);
String timeAns = "";
for (int pp : ancestorDurations) {
timeAns += (pp * BuildNet.TIME_STEP) + " ";
}
// String timeAns = "";
// for (int pp : ancestorDurations) {
// timeAns += (pp * BuildNet.TIME_STEP) + " ";
// }
// System.out.println(timeAns);
double temperature = thermoDynamics.calculateTemperature(functionCall);
@@ -89,20 +88,20 @@ public MathController() {
}
private void printPermuatation(int[] permutation) {
String out = "";
for (int p : permutation) {
p *= BuildNet.TIME_STEP;
out += p + "\t";
}
System.out.println(out);
}
// @SuppressWarnings("unused")
// private double randomRadiationDistributed() {
// Random generator = new Random();
// int rnd = generator.nextInt(BuildNet.radiationDistribution.length);
// private void printPermuatation(int[] permutation) {
// String out = "";
// for (int p : permutation) {
// p *= BuildNet.TIME_STEP;
// out += p + "\t";
// }
//
// System.out.println(out);
// }
//
// // @SuppressWarnings("unused")
// // private double randomRadiationDistributed() {
// // Random generator = new Random();
// // int rnd = generator.nextInt(BuildNet.radiationDistribution.length);
// return BuildNet.radiationDistribution[rnd];
// }
//
Oops, something went wrong.

0 comments on commit db54f9c

Please sign in to comment.