Mercurial > hg > jslab
view src/samer/maths/random/BinaryVec.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. */ /* Similar to binary, but has different bit probabilities for elements of vector */ package samer.maths.random; import samer.maths.*; import samer.core.types.*; public class BinaryVec extends BaseRandom { int n; VVector probs; double [] p; boolean ownp; public BinaryVec(int n, double pp) { this(new VVector("probs",n)); ownp=true; for (int i=0; i<n; i++) p[i]=pp; } public BinaryVec(VVector probs) { this.n=probs.size(); this.probs=probs; p=probs.array(); ownp=false; } public int getSize() { return n; } public void dispose() { if (ownp) probs.dispose(); } public double next() { return (rnd.nextDouble()<p[0]) ? 1.0 : 0.0; } public void next(double [] x) { int i, j; for (i=0,j=0; i<x.length; i++,j++) { if (j>=n) j=0; x[i]=(rnd.nextDouble()<p[j]) ? 1.0 : 0.0; } } }