mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
Changed the place of index_to_slices to more logical place
This commit is contained in:
parent
0c6438608d
commit
0b5e8d895e
9 changed files with 35 additions and 34 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
|
||||||
from .kern import Kern
|
from .kern import Kern
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
from ...core.parameterization import Param
|
from ...core.parameterization import Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from .kern import Kern
|
||||||
from ...core.parameterization import Param
|
from ...core.parameterization import Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
|
|
||||||
class ODE_UYC(Kern):
|
class ODE_UYC(Kern):
|
||||||
def __init__(self, input_dim, variance_U=3., variance_Y=1., lengthscale_U=1., lengthscale_Y=1., ubias =1. ,active_dims=None, name='ode_uyc'):
|
def __init__(self, input_dim, variance_U=3., variance_Y=1., lengthscale_U=1., lengthscale_Y=1., ubias =1. ,active_dims=None, name='ode_uyc'):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .kern import Kern
|
||||||
from ...core.parameterization import Param
|
from ...core.parameterization import Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
|
|
||||||
|
|
||||||
class ODE_st(Kern):
|
class ODE_st(Kern):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from .kern import Kern
|
||||||
from ...core.parameterization import Param
|
from ...core.parameterization import Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
|
|
||||||
|
|
||||||
class ODE_t(Kern):
|
class ODE_t(Kern):
|
||||||
|
|
|
||||||
|
|
@ -5,34 +5,8 @@
|
||||||
from .kern import CombinationKernel
|
from .kern import CombinationKernel
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import itertools
|
import itertools
|
||||||
|
from GPy.util.multioutput import index_to_slices
|
||||||
|
|
||||||
def index_to_slices(index):
|
|
||||||
"""
|
|
||||||
take a numpy array of integers (index) and return a nested list of slices such that the slices describe the start, stop points for each integer in the index.
|
|
||||||
|
|
||||||
e.g.
|
|
||||||
>>> index = np.asarray([0,0,0,1,1,1,2,2,2])
|
|
||||||
returns
|
|
||||||
>>> [[slice(0,3,None)],[slice(3,6,None)],[slice(6,9,None)]]
|
|
||||||
|
|
||||||
or, a more complicated example
|
|
||||||
>>> index = np.asarray([0,0,1,1,0,2,2,2,1,1])
|
|
||||||
returns
|
|
||||||
>>> [[slice(0,2,None),slice(4,5,None)],[slice(2,4,None),slice(8,10,None)],[slice(5,8,None)]]
|
|
||||||
"""
|
|
||||||
if len(index)==0:
|
|
||||||
return[]
|
|
||||||
|
|
||||||
#contruct the return structure
|
|
||||||
ind = np.asarray(index,dtype=np.int)
|
|
||||||
ret = [[] for i in range(ind.max()+1)]
|
|
||||||
|
|
||||||
#find the switchpoints
|
|
||||||
ind_ = np.hstack((ind,ind[0]+ind[-1]+1))
|
|
||||||
switchpoints = np.nonzero(ind_ - np.roll(ind_,+1))[0]
|
|
||||||
|
|
||||||
[ret[ind_i].append(slice(*indexes_i)) for ind_i,indexes_i in zip(ind[switchpoints[:-1]],zip(switchpoints,switchpoints[1:]))]
|
|
||||||
return ret
|
|
||||||
|
|
||||||
class IndependentOutputs(CombinationKernel):
|
class IndependentOutputs(CombinationKernel):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from .kern import Kern, CombinationKernel
|
from .kern import Kern, CombinationKernel
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from functools import reduce, partial
|
from functools import reduce, partial
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
from paramz.caching import Cache_this
|
from paramz.caching import Cache_this
|
||||||
|
|
||||||
class ZeroKern(Kern):
|
class ZeroKern(Kern):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ A new kernel
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .kern import Kern, CombinationKernel
|
from .kern import Kern, CombinationKernel
|
||||||
from .independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
class DEtime(Kern):
|
class DEtime(Kern):
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from .gaussian import Gaussian
|
||||||
from ..core.parameterization import Param
|
from ..core.parameterization import Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
from ..core.parameterization import Parameterized
|
from ..core.parameterization import Parameterized
|
||||||
from ..kern.src.independent_outputs import index_to_slices
|
from GPy.util.multioutput import index_to_slices
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
class MultioutputLikelihood(MixedNoise):
|
class MultioutputLikelihood(MixedNoise):
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,33 @@ import numpy as np
|
||||||
import warnings
|
import warnings
|
||||||
import GPy
|
import GPy
|
||||||
|
|
||||||
|
def index_to_slices(index):
|
||||||
|
"""
|
||||||
|
take a numpy array of integers (index) and return a nested list of slices such that the slices describe the start, stop points for each integer in the index.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
>>> index = np.asarray([0,0,0,1,1,1,2,2,2])
|
||||||
|
returns
|
||||||
|
>>> [[slice(0,3,None)],[slice(3,6,None)],[slice(6,9,None)]]
|
||||||
|
|
||||||
|
or, a more complicated example
|
||||||
|
>>> index = np.asarray([0,0,1,1,0,2,2,2,1,1])
|
||||||
|
returns
|
||||||
|
>>> [[slice(0,2,None),slice(4,5,None)],[slice(2,4,None),slice(8,10,None)],[slice(5,8,None)]]
|
||||||
|
"""
|
||||||
|
if len(index)==0:
|
||||||
|
return[]
|
||||||
|
|
||||||
|
#contruct the return structure
|
||||||
|
ind = np.asarray(index,dtype=np.int)
|
||||||
|
ret = [[] for i in range(ind.max()+1)]
|
||||||
|
|
||||||
|
#find the switchpoints
|
||||||
|
ind_ = np.hstack((ind,ind[0]+ind[-1]+1))
|
||||||
|
switchpoints = np.nonzero(ind_ - np.roll(ind_,+1))[0]
|
||||||
|
|
||||||
|
[ret[ind_i].append(slice(*indexes_i)) for ind_i,indexes_i in zip(ind[switchpoints[:-1]],zip(switchpoints,switchpoints[1:]))]
|
||||||
|
return ret
|
||||||
|
|
||||||
def get_slices(input_list):
|
def get_slices(input_list):
|
||||||
num_outputs = len(input_list)
|
num_outputs = len(input_list)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue