Mercurial > hg > jslab
view src/samer/units/Latch.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.units; import samer.core.*; import samer.core.types.*; import samer.tools.*; import samer.maths.*; import java.util.*; /** Temporally smoothed thresholding latch */ public class Latch extends NamedTask { VDouble thresh; VInteger countThresh; boolean [] states; int [] counts; VVector output; double[] in,out; int n; public Latch(VVector input) { super("latch"); n = input.size(); states = new boolean[n]; counts = new int[n]; Shell.push(node); thresh = new VDouble("thresh",0.5); countThresh = new VInteger("count_thresh",3); output = new VVector("output", n); Shell.pop(); in=input.array(); out=output.array(); } public VVector output() { return output; } public void run() { for (int i=0; i<n; i++) { if (!states[i]) { // unit is off - check to see if it should be on if (in[i]>thresh.value) { if (++counts[i] >= countThresh.value) { out[i]=in[i]; states[i]=true; counts[i]=0; } } else counts[i]=0; } else { // note is on - see about switching it off if (in[i]<=0.8*thresh.value) { if (++counts[i] >= countThresh.value) { out[i]=-1; states[i]=false; counts[i]=0; } else out[i]=in[i]; } else { counts[i]=0; out[i]=in[i]; } } } output.changed(); } }