This provides a simple base implementation for the cache related methods in Kernel Trick. By default they will all call #eval(jsat.linear.Vec, jsat.linear.Vec) directly. For this reason #supportsAcceleration() defaults to returning false. If the Kernel supports cache acceleration,
| 16 | * @author Edward Raff |
| 17 | */ |
| 18 | public abstract class BaseKernelTrick implements KernelTrick |
| 19 | { |
| 20 | private static final long serialVersionUID = 7230585838672226751L; |
| 21 | |
| 22 | @Override |
| 23 | public boolean supportsAcceleration() |
| 24 | { |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public List<Double> getAccelerationCache(List<? extends Vec> trainingSet) |
| 30 | { |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public List<Double> getQueryInfo(Vec q) |
| 36 | { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void addToCache(Vec newVec, List<Double> cache) |
| 42 | { |
| 43 | |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public double eval(int a, int b, List<? extends Vec> trainingSet, List<Double> cache) |
| 48 | { |
| 49 | return eval(trainingSet.get(a), trainingSet.get(b)); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public double eval(int a, Vec b, List<Double> qi, List<? extends Vec> vecs, List<Double> cache) |
| 54 | { |
| 55 | return eval(vecs.get(a), b); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public double evalSum(List<? extends Vec> finalSet, List<Double> cache, double[] alpha, Vec y, int start, int end) |
| 60 | { |
| 61 | return evalSum(finalSet, cache, alpha, y, getQueryInfo(y), start, end); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public double evalSum(List<? extends Vec> finalSet, List<Double> cache, double[] alpha, Vec y, List<Double> qi, int start, int end) |
| 66 | { |
| 67 | double sum = 0; |
| 68 | |
| 69 | for(int i = start; i < end; i++) |
| 70 | sum += alpha[i] * eval(i, y, qi, finalSet, cache); |
| 71 | |
| 72 | return sum; |
| 73 | } |
| 74 | |
| 75 | @Override |
nothing calls this directly
no outgoing calls
no test coverage detected