![JAR search and dependency download from the Maven repository](/logo.png)
com.simiacryptus.mindseye.network.GraphEvaluationContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindseye-core Show documentation
Show all versions of mindseye-core Show documentation
Core Neural Networks Framework
/*
* Copyright (c) 2019 by Andrew Charneski.
*
* The author licenses this file to you under the
* Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.simiacryptus.mindseye.network;
import com.simiacryptus.lang.ref.ReferenceCountingBase;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
/**
* This class provides the index for re-using the output of any given node during a single network evaluation, such that
* each node is executed minimally.
*/
class GraphEvaluationContext extends ReferenceCountingBase {
/**
* The Expected counts.
*/
final Map expectedCounts = new ConcurrentHashMap<>();
/**
* The Calculated.
*/
final Map> calculated = new ConcurrentHashMap<>();
@Override
protected synchronized void _free() {
calculated.entrySet().stream().filter(e -> {
Object o = e.getValue().get();
if (o instanceof RuntimeException) throw (RuntimeException) o;
if (o instanceof Throwable) throw new RuntimeException((Throwable) o);
CountingResult countingNNResult = (CountingResult) o;
if (expectedCounts.containsKey(e.getKey())) {
return expectedCounts.get(e.getKey()) > countingNNResult.getAccumulator().getCount();
} else {
return true;
}
}).forEach(x -> {
CountingResult result = x.getValue().get();
result.freeRef();
result.getData().freeRef();
});
calculated.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy