Calculate PI output value for given reference input and feedback
353257
def controler_output(self, current_value):
        

        set_point = self.settings['set_point']
        Kp = self.settings['gains']['proportional']
        Ki = self.settings['gains']['integral']
        output_range = self.settings['output_range']
        time_step = self.settings['time_step']

        error_new = set_point - current_value
        print(('PD- error:\t', error_new, Ki, Kp, time_step))
        #proportional action
        self.u_P = Kp * error_new * time_step
        print(('PD- self.u_P:\t', self.u_P, self.u_I))

        #integral action
        self.u_I += Kp * Ki * (error_new + self.error) / 2.0 * time_step

        self.error = error_new

        print(('PD- self.u_P:\t', self.u_P, self.u_I))

        # anti-windup
        if self.u_P + self.u_I > output_range['max']:
            self.u_I = output_range['max']-self.u_P
        if self.u_P + self.u_I < output_range['min']:
            self.u_I = output_range['min']-self.u_P


        output = self.u_P + self.u_I
        print(('PD- output:\t', output))
        return output
787409
def calc_metric(self, is_correct: bool, actual_output: bool, threshold=0.5) -> int:
        """"""
        return int(
            ((((self.outputs > threshold) == self.targets.astype(bool)) == is_correct) &
             ((self.outputs > threshold) == actual_output)).sum()
        )
142197
def pi (self, data):
        
        data = data.encode(self.encoding, "ignore")
        self.fd.write("<?%s?>" % data)
1109825
def set_output_port(self, new_value, old_value=0):
        """"""
        print("Setting output port to {}.".format(new_value))
        port_value = old_value
        try:
            port_value = int(new_value)  # dec
        except ValueError:
            port_value = int(new_value, 16)  # hex
        finally:
            self.pifacedigital.output_port.value = port_value
            return port_value
1128860
function y2lat(y) {
  return 360 / Math.PI * Math.atan(Math.exp(y * Math.PI / 180)) - 90;
}
627934
def ParallelCalculate(cls,syslst,properties=['energy'],system_changes=all_changes):
        '''
        
        '''
        print('Launching:',end=' ')
        sys.stdout.flush()
        for n,s in enumerate(syslst):
            try :
                s.calc.block=False
                s.calc.calculate(atoms=s,properties=properties,system_changes=system_changes)
            except CalcNotReadyError:
                s.calc.block=True
            print(n+1, end=' ')
            sys.stdout.flush()
        print()
        print('     Done:', end=' ')
        sys.stdout.flush()
        for n,s in enumerate(syslst):
            s.calc.read_results()
            print( n+1, end=' ')
            sys.stdout.flush()
        print()
        return syslst
1016289
def compute(self, inputs, outputs):
    
    if len(self.queue) > 0:
      # Take the top element of the data queue
      data = self.queue.pop()
    else:
      raise Exception("RawValues: No data: queue is empty ")

    # Copy data into output vectors
    outputs["resetOut"][0] = data["reset"]
    outputs["dataOut"][:] = data["dataOut"]
454310
private int dpToPx(float dp) {
        final DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics);
        return Math.round(px);
    }
546968
protected static double computeH(DBIDRef ignore, DoubleDBIDListIter it, double[] p, double mbeta) {
    double sumP = 0.;
    // Skip point "i", break loop in two:
    it.seek(0);
    for(int j = 0; it.valid(); j++, it.advance()) {
      if(DBIDUtil.equal(ignore, it)) {
        p[j] = 0;
        continue;
      }
      sumP += (p[j] = FastMath.exp(it.doubleValue() * mbeta));
    }
    if(!(sumP > 0)) {
      // All pij are zero. Bad news.
      return Double.NEGATIVE_INFINITY;
    }
    final double s = 1. / sumP; // Scaling factor
    double sum = 0.;
    // While we could skip pi[i], it should be 0 anyway.
    it.seek(0);
    for(int j = 0; it.valid(); j++, it.advance()) {
      sum += it.doubleValue() * (p[j] *= s);
    }
    return FastMath.log(sumP) - mbeta * sum;
  }
676712
def calculate_gyro_calibration(self, gyro_samples):
        """"""

        totals = [0, 0, 0]
        for gs in gyro_samples:
            totals[0] += gs[0]
            totals[1] += gs[1]
            totals[2] += gs[2]

        for i in range(3):
            totals[i] = int(float(totals[i]) / len(gyro_samples))

        print('Saving gyro offsets for {}'.format(self.current_imuid))
        self.calibration_data[self.current_imuid][self.GYROX_OFFSET] = str(totals[0])
        self.calibration_data[self.current_imuid][self.GYROY_OFFSET] = str(totals[1])
        self.calibration_data[self.current_imuid][self.GYROZ_OFFSET] = str(totals[2])
        self.calibration_data[self.current_imuid][self.GYRO_TIMESTAMP] = datetime.now().isoformat()
        self.write_calibration_data()
        self.update_data_display(self.calibration_data[self.current_imuid])
        self.calibration_state = self.CAL_NONE
1356542
def output(output_id, name, value_class=NumberValue):
        """"""
        def _init():
            return value_class(
                name,
                input_id=output_id,
                is_input=False,
                index=-1
            )
        def _decorator(cls):
            setattr(cls, output_id, _init())
            return cls
        return _decorator
435682
def updateOutputValues(self,output_wcs):
        
        outputvals = self.outputValues

        outputvals['output'] = output_wcs.outputNames['outFinal']
        outputvals['outnx'], outputvals['outny'] = output_wcs.wcs.pixel_shape
        outputvals['texptime'] = output_wcs._exptime
        outputvals['texpstart'] = output_wcs._expstart
        outputvals['texpend'] = output_wcs._expend
        outputvals['nimages'] = output_wcs.nimages

        outputvals['scale'] = output_wcs.wcs.pscale #/ self._image[self.scienceExt,1].wcs.pscale
        outputvals['exptime'] = self._exptime

        outnames = self.outputNames
        outnames['outMedian'] = output_wcs.outputNames['outMedian']
        outnames['outFinal'] = output_wcs.outputNames['outFinal']
        outnames['outSci'] = output_wcs.outputNames['outSci']
        outnames['outWeight'] = output_wcs.outputNames['outWeight']
        outnames['outContext'] = output_wcs.outputNames['outContext']
945781
function get(n = 200) {
    if (!isPositiveInt(n)) return '0'; // return 0 if a valid value was not passed
    if (n === 0) return '3'; // skip calculations

    let p16 = new Decimal(1);
    let pi = new Decimal(0);

    // Check if pi value is already cached
    const cachedPI = cachePI.get('cachedPI');
    if (cachedPI) {
        pi = cachedPI; // set the value from cache
    } else {
        // Check the precision needed
        const precision = Decimal.config({}).precision;
        const one = new Decimal(1);
        const two = new Decimal(2);
        const four = new Decimal(4);
        let k8 = new Decimal(0);

        for (let k = new Decimal(0); k.lte(precision); k = k.plus(one)) {
            const f = four
                .div(k8.plus(1))
                .minus(two.div(k8.plus(4)))
                .minus(one.div(k8.plus(5)))
                .minus(one.div(k8.plus(6)));

            pi = pi.plus(p16.times(f));
            p16 = p16.div(16);
            k8 = k8.plus(8);
        }

        // Cache the original pi value here
        cachePI.set('cachedPI', pi);
    }

    // validate number of places needed
    n = n > 200 ? 200 : n;
    return pi.toPrecision(n + 2).slice(0, -1);
}
18283
def PC_PI_calc(P, TOP, POP):
    
    try:
        result = 0
        for i in P.keys():
            result += ((P[i] + TOP[i]) / (2 * POP[i]))**2
        return result
    except Exception:
        return "None"
1069952
def _get_output(algorithm, iport=0, iconnection=0, oport=0, active_scalar=None,
                active_scalar_field='point'):
    """"""
    ido = algorithm.GetInputDataObject(iport, iconnection)
    data = wrap(algorithm.GetOutputDataObject(oport))
    data.copy_meta_from(ido)
    if active_scalar is not None:
        data.set_active_scalar(active_scalar, preference=active_scalar_field)
    return data
813744
def dpsi2_dmuS(self, dL_dpsi2, Z, mu, S, target_mu, target_S):
        
        self._psi_computations(Z, mu, S)
        tmp = (self.inv_lengthscale2 * self._psi2[:, :, :, None]) / self._psi2_denom
        target_mu += -2.*(dL_dpsi2[:, :, :, None] * tmp * self._psi2_mudist).sum(1).sum(1)
        target_S += (dL_dpsi2[:, :, :, None] * tmp * (2.*self._psi2_mudist_sq - 1)).sum(1).sum(1)
880561
def value(self, t):
        """"""
        fraction = min(float(t) / max(1, self.schedule_timesteps), 1.0)
        return self.initial_p + fraction * (self.final_p - self.initial_p)