$$\frac{dy(t)}{dt} = -y(t),$$

$$\frac{dy(t, {n_i})}{dt} + y(t,{n_i}) = 0,$$

$$\text{waste} = \frac{dy(t, {n_i})}{dt} + y(t,{n_i}) ,$$

$$\text{cost} = \int dt ( \frac{dy(t, {n_i})}{dt} + y(t,{n_i}) )^2.$$

## 人工神经网络参数化

$$\text{sigmoid}(t) = \frac{1}{1+e^{-t}}.$$

$$y(t)= y(0)+t \sum_k v_k f(t w_k+u_k).$$

$w_k$ 是对启动函数的缩放，$u_k$ 是对启动函数的平移，而 $v_k$ 的作用是放大缩小函数值。可以设想，当我们的参数足够多的时候，我们可以用这个参数化来组成任何连续函数。

## cost

$$\text{cost} = \int dt ( \frac{dy(t, {n_i})}{dt} + y(t,{n_i}) )^2.$$

$$\text{cost} = \sum_j \left(\frac{dy(t_j, {n_i})}{dt} + y(t_j,{n_i}) \right)^2.$$

$$\frac{dy(t, {n_i})}{dt} + y(t,{n_i}) = 0,$$

$$y(t)= y(0)+t \sum_k v_k f(t w_k+u_k),$$

$$\text{cost} = \sum_j \frac{dy(t_j, {n_i})}{dt} + y(t_j,{n_i}) )^2.$$

## 代码举例

{% highlight python %} import numpy as np from scipy.optimize import minimize from scipy.special import expit import matplotlib.pyplot as plt

def cost(v,w,u,t): v = np.array(v) # Don’t know why but np.asarray(v) doesn’t work here. w = np.array(w) u = np.array(u)

fvec = np.array(trigf(t*w + u) )  # This is a vector!!!
yt = 1 + np.sum ( t * v * fvec  )  # For a given t, this calculates the value of y(t), given the parameters, v, w, u.
return  ( np.sum (v*fvec + t * v* fvec * ( 1 -  fvec  ) * w ) + yt )   ** 2


def trigf(x): #return 1/(1+np.exp(-x)) # return expit(x)

def costTotal(v,w,u,t): t = np.array(t) costt = 0 for temp in t: costt = costt + cost(v,w,u,temp) return costt

costTotalF = lambda x: costTotal(np.split(x,3)[0],np.split(x,3)[1],np.split(x,3)[2],tlin)

initGuess = np.zeros(30) result = minimize(costTotalF,initGuess,method="SLSQP”) {% endhighlight %}

Published: by ;