Java Code Examples for org.deeplearning4j.arbiter.optimize.api.ParameterSpace#isLeaf()
The following examples show how to use
org.deeplearning4j.arbiter.optimize.api.ParameterSpace#isLeaf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayerSpace.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public List<ParameterSpace> collectLeaves() { //To avoid manually coding EVERY parameter, in every layer: // Do a depth-first search of nested spaces LinkedList<ParameterSpace> stack = new LinkedList<>(); stack.add(this); List<ParameterSpace> out = new ArrayList<>(); while (!stack.isEmpty()) { ParameterSpace next = stack.removeLast(); if (next.isLeaf()) { out.add(next); } else { Map<String, ParameterSpace> m = next.getNestedSpaces(); ParameterSpace[] arr = m.values().toArray(new ParameterSpace[m.size()]); for (int i = arr.length - 1; i >= 0; i--) { stack.add(arr[i]); } } } return out; }
Example 2
Source File: BaseNetworkSpace.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public List<ParameterSpace> collectLeaves() { Map<String, ParameterSpace> global = getNestedSpaces(); //Note: Results on previous line does NOT include the LayerSpaces, therefore we need to add these manually... //This is because the type is a list, not a ParameterSpace LinkedList<ParameterSpace> stack = new LinkedList<>(); stack.add(this); for (LayerConf layerConf : layerSpaces) { LayerSpace ls = layerConf.getLayerSpace(); stack.addAll(ls.collectLeaves()); } List<ParameterSpace> out = new ArrayList<>(); while (!stack.isEmpty()) { ParameterSpace next = stack.removeLast(); if (next.isLeaf()) { out.add(next); } else { Map<String, ParameterSpace> m = next.getNestedSpaces(); ParameterSpace[] arr = m.values().toArray(new ParameterSpace[m.size()]); for (int i = arr.length - 1; i >= 0; i--) { stack.add(arr[i]); } } } return out; }
Example 3
Source File: ParameterSpaceAdapter.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public List<ParameterSpace> collectLeaves() { ParameterSpace p = underlying(); if(p.isLeaf()){ return Collections.singletonList(p); } return underlying().collectLeaves(); }
Example 4
Source File: LeafUtils.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Count the number of unique parameters in the specified leaf nodes * * @param allLeaves Leaf values to count the parameters fore * @return Number of parameters for all unique objects */ public static int countUniqueParameters(List<ParameterSpace> allLeaves) { List<ParameterSpace> unique = getUniqueObjects(allLeaves); int count = 0; for (ParameterSpace ps : unique) { if (!ps.isLeaf()) { throw new IllegalStateException("Method should only be used with leaf nodes"); } count += ps.numParameters(); } return count; }