Compare commits
3 commits
5aa9313776
...
fc1d803c99
Author | SHA1 | Date | |
---|---|---|---|
fc1d803c99 | |||
69a6c8df29 | |||
8376c00470 |
4 changed files with 50 additions and 12 deletions
|
@ -4,14 +4,8 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="75a8c215-b746-4a4d-aa16-f3223c12b1ed" name="Changes" comment="Commented out not yet working code">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/ActivationFunctions.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/LossFunctions.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/ActivationLayer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ActivationLayer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/ExampleXOR.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ExampleXOR.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Network.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Network.java" afterDir="false" />
|
||||
<list default="true" id="75a8c215-b746-4a4d-aa16-f3223c12b1ed" name="Changes" comment="Added MAE loss function">
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/ActivationFunctions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ActivationFunctions.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -103,7 +97,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1653168727186</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<task id="LOCAL-00002" summary="Added MAE loss function">
|
||||
<created>1653176561735</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1653176561735</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="3" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -120,7 +121,8 @@
|
|||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Initial commit" />
|
||||
<MESSAGE value="Commented out not yet working code" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Commented out not yet working code" />
|
||||
<MESSAGE value="Added MAE loss function" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Added MAE loss function" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/JavaNN$ExampleXOR.ic" NAME="ExampleXOR Coverage Results" MODIFIED="1653174521293" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
|
||||
|
|
|
@ -36,4 +36,20 @@ public class ActivationFunctions {
|
|||
private static double sigma(double value) {
|
||||
return 1 / (1 + Math.exp(-value));
|
||||
}
|
||||
|
||||
public static SimpleMatrix ReLu(SimpleMatrix A) {
|
||||
SimpleMatrix B = new SimpleMatrix(A);
|
||||
for (int i = 0; i < A.getNumElements(); i++) {
|
||||
B.set(i, Math.max(0, A.get(i)));
|
||||
}
|
||||
return B;
|
||||
}
|
||||
|
||||
public static SimpleMatrix ReLuPrime(SimpleMatrix A) {
|
||||
SimpleMatrix B = new SimpleMatrix(A);
|
||||
for (int i = 0; i < A.getNumElements(); i++) {
|
||||
B.set(i, A.get(i) < 0 ? 0 : 1);
|
||||
}
|
||||
return B;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ public class FCLayer extends Layer {
|
|||
public FCLayer(int inputSize, int outputSize) {
|
||||
Random random = new Random();
|
||||
weights = new SimpleMatrix(inputSize, outputSize, true,
|
||||
random.doubles((long) inputSize*outputSize, -0.5, 0.5).toArray());
|
||||
random.doubles((long) inputSize*outputSize, -1, 1).toArray());
|
||||
biases = new SimpleMatrix(1, outputSize, true,
|
||||
random.doubles(outputSize, -0.5, 0.5).toArray());
|
||||
random.doubles(outputSize, -1, 1).toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,4 +14,24 @@ public class LossFunctions {
|
|||
public static SimpleMatrix MSEPrime(SimpleMatrix y_true, SimpleMatrix y_pred) {
|
||||
return y_true.minus(y_pred).divide((double) y_true.getNumElements()/2);
|
||||
}
|
||||
|
||||
public static double MAE(SimpleMatrix y_true, SimpleMatrix y_pred) {
|
||||
double sum = 0;
|
||||
for (int i = 0; i < y_true.getNumElements(); i++) {
|
||||
sum += Math.abs(y_true.get(i) - y_pred.get(i));
|
||||
}
|
||||
return sum / y_true.getNumElements();
|
||||
}
|
||||
|
||||
public static SimpleMatrix MAEPrime(SimpleMatrix y_true, SimpleMatrix y_pred) {
|
||||
SimpleMatrix result = new SimpleMatrix(y_true);
|
||||
for (int i = 0; i < result.getNumElements(); i++) {
|
||||
if (y_true.get(i) < y_pred.get(i)) {
|
||||
result.set(i, 1d);
|
||||
} else {
|
||||
result.set(i, -1d);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue