Added ReLu activation function

This commit is contained in:
lluni 2022-05-22 01:47:39 +02:00
parent 69a6c8df29
commit fc1d803c99
2 changed files with 28 additions and 5 deletions

View file

@ -4,9 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="75a8c215-b746-4a4d-aa16-f3223c12b1ed" name="Changes" comment="Commented out not yet working code"> <list default="true" id="75a8c215-b746-4a4d-aa16-f3223c12b1ed" name="Changes" comment="Added MAE loss function">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ActivationFunctions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ActivationFunctions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/LossFunctions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/LossFunctions.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -98,7 +97,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1653168727186</updated> <updated>1653168727186</updated>
</task> </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 /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -115,7 +121,8 @@
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="Initial commit" /> <MESSAGE value="Initial commit" />
<MESSAGE value="Commented out not yet working code" /> <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>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <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" /> <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" />

View file

@ -36,4 +36,20 @@ public class ActivationFunctions {
private static double sigma(double value) { private static double sigma(double value) {
return 1 / (1 + Math.exp(-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;
}
} }