Skip to content

Commit

Permalink
Add layer method
Browse files Browse the repository at this point in the history
  • Loading branch information
xEcho1337 committed Oct 22, 2024
1 parent 243695c commit b420cfb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/net/echo/brain4j/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,11 @@ public interface Model {
* @param path path to save model
*/
void save(String path);

/**
* Adds a layer to the network.
*
* @param layer the layer to add
*/
void add(Layer layer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class FeedForwardModel implements Model {

Expand Down Expand Up @@ -110,7 +111,8 @@ public double[] predict(double ... input) {
Layer inputLayer = layers.get(0);

if (input.length != inputLayer.getNeurons().size()) {
throw new IllegalArgumentException("Input size does not match model's input dimension!");
throw new IllegalArgumentException("Input size does not match model's input dimension! " +
input.length + " != " + inputLayer.getNeurons().size());
}

for (Layer layer : layers) {
Expand Down Expand Up @@ -278,4 +280,9 @@ public void save(String path) {
throw new RuntimeException(e);
}
}

@Override
public void add(Layer layer) {
layers.add(layer);
}
}

0 comments on commit b420cfb

Please sign in to comment.