private double[] checkWeights(double[] weights){

        // Make all weights positive and check if all zero
        int nZeros = 0;
        for(int i=0; i<this.nWeights; i++){
            weights[i] = Math.abs(weights[i]);
            if(weights[i]==0.0)nZeros++;
        }
        // if all zeros replace all by unity
        if(nZeros==this.nWeights){
            for(int i=0; i<this.nWeights; i++){
                weights[i] = 1.0;
            }
        }

        // Calculate mean and sd
        Stat stat= new Stat(weights);
        this.weightsMean = stat.mean();
        this.weightsSD = stat.standardDeviation();

        // check for zero and replace by mean/100
        for(int i=0; i<this.nWeights; i++){
            if(weights[i]==0.0){
                weights[i] = this.weightsMean/100.0;
                System.out.println("Weight at point " + i + " is zero; replaced by a value " + this.weightsMean/100.0);
            }
        }

        return weights;
    }