def __autocorrelation__(v, mode=1, norm=False, detrend=False): """ A simple function for performing the autocorrelation by either Wiener–Khinchin theorem using FFT, or by using the following expression: C(tau) = <v(t) . v(t+tau)> ; where <...> is ensemble averaged over time origins, t, and tau is the time delay. It is recommended to use the FFT method for speed unless you have a good reason not to do so. Generally, this function does not need to be implemented, because it is explicitely written for 1D arrays, and instead you should run autocorrelation(), which will decide if your data contains vectors, this function is the workhorse behind that function. Args: v: [array] the data for which to get the autocorrelation mode: (int) which mode to run this function. 1 is FFT based, and 2 follows the above formula. default=1. norm: (bool) whether or not to normalize the ACF data to 1. Generally, for correlation functions in statistical mechanics, you do not want to normalize, because the area under the curve is connected to the transport coefficients (see, Green-Kubo formalism). Default=False detrend: (bool) Whether or not to de-trend the data by subtracting the mean from each element of v Returns: [array] the autocorrelation results """ nstep = len(v) # Number of time steps i.e. number of data points c = np.zeros((nstep, ), dtype=float) # empty array for the correlation data if detrend: v = np.subract(v, np.mean(v)) # FFT Method if mode == 1: vv = np.concatenate( (v[::-1], v[1:])) # Mirror the data (FFT assumes periodicity) vv0 = np.concatenate((vv, np.zeros( (2 * nstep, ), dtype=float))) # Pad the data with 0's (FFT assumes periodicity) c = np.fft.ifft(np.abs(np.power( np.fft.fft(v), 2)))[:nstep].real # Wiener–Khinchin, only take half mirror # Discrete Method if mode == 2: vv = np.concatenate((v, np.zeros((nstep, ), dtype=float))) for t in range(nstep): for j in range(nstep): c[t] += v[j] * vv[j + t] c = c / nstep if norm: c = c / np.max(c) return c[0:int(len(v))]
def perceptrontrain(): inputsize = 4 numinputs = 10 bias = 0.0 initialweights = np.random.rand(inputsize) inputdata = np.random.rand(numinputs,inputsize) outputdata = np.random.rand(numinputs) weighted = np.multiply(inputdata,initialweights) summed = np.sum(weighted,1) biased = np.subtract(summed,bias) errors = np.subract(outputdata,biased) totalerror = np.sum(errors) return totalerror
def f_delta(cls,x): return np.multiply(cls.f(x),np.subract(1 , cls.f(x)))
def Subadditive(X, Y, METRIC): return np.sum(np.abs(np.subract(X,CENTER)),0)<=np.subtract(np.sum(np.abs(X),0),np.sum(np.abs(CENTER),0))