Documentation
¶
Overview ¶
implements neural networks and he neural networks interfaces
Index ¶
- type HENetwork
- func (n *HENetwork) CheckLvlAtLayer(level, minLevel, layer int, forAct, afterMul bool) bool
- func (n *HENetwork) Eval(X cipherUtils.BlocksOperand) (*cipherUtils.EncInput, time.Duration)
- func (n *HENetwork) EvalDebug(Xenc cipherUtils.BlocksOperand, Xclear *mat.Dense, network NetworkI, ...) (*cipherUtils.EncInput, *mat.Dense, time.Duration)
- func (n *HENetwork) GetBox() cipherUtils.CkksBox
- func (n *HENetwork) GetRotations(params ckks.Parameters, btpParams *bootstrapping.Parameters) []int
- func (n *HENetwork) IsInit() bool
- func (n *HENetwork) LevelsToComplete(currLayer int, afterMul bool) int
- func (n *HENetwork) SetBox(box cipherUtils.CkksBox)
- type HENetworkI
- type Initiator
- type Network
- func (n *Network) CheckLvlAtLayer(level, minLevel, layer int, forAct, afterMul bool) bool
- func (n *Network) GetActivations() []utils.ChebyPolyApprox
- func (n *Network) GetDimentions() ([]int, []int)
- func (n *Network) GetNumOfActivations() int
- func (n *Network) GetNumOfLayers() int
- func (n *Network) GetParams() ([]*mat.Dense, []*mat.Dense)
- func (n *Network) GetParamsRescaled() ([]*mat.Dense, []*mat.Dense)
- func (n *Network) IsInit() bool
- func (n *Network) LevelsToComplete(currLayer int, afterMul bool) int
- func (n *Network) NewHE(splits *cipherUtils.Split, encrypted, bootstrappable bool, ...) HENetworkI
- func (n *Network) SetActivations(activations []utils.ChebyPolyApprox)
- func (n *Network) SetBatch(batchSize int)
- func (n *Network) SetLayers(layers []utils.Layer)
- type NetworkI
- type NetworkJ
- type NetworkLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HENetwork ¶
type HENetwork struct { Weights []cipherUtils.BlocksOperand Bias []cipherUtils.BlocksOperand Multiplier *cipherUtils.Multiplier Adder *cipherUtils.Adder Activator *cipherUtils.Activator Bootstrapper cipherUtils.IBootstrapper Bootstrappable bool MinLevel int BtpCapacity int NumOfLayers int Box cipherUtils.CkksBox // contains filtered or unexported fields }
Network for HE, either in clear or encrypted The implemented network should evaluate layers as: Activation(Input * Weight + bias)
func (*HENetwork) CheckLvlAtLayer ¶
true if he version needs bootstrapping at this layer with level = level
func (*HENetwork) Eval ¶
func (n *HENetwork) Eval(X cipherUtils.BlocksOperand) (*cipherUtils.EncInput, time.Duration)
Runs inference
func (*HENetwork) EvalDebug ¶
func (n *HENetwork) EvalDebug(Xenc cipherUtils.BlocksOperand, Xclear *mat.Dense, network NetworkI, L1thresh float64) (*cipherUtils.EncInput, *mat.Dense, time.Duration)
Eval but with debug statements for checking the HE pipeline step by step
func (*HENetwork) GetBox ¶
func (n *HENetwork) GetBox() cipherUtils.CkksBox
func (*HENetwork) GetRotations ¶
func (n *HENetwork) GetRotations(params ckks.Parameters, btpParams *bootstrapping.Parameters) []int
Generate the rotations needed to evaluate the network and updates the network box with the rotation keys
func (*HENetwork) LevelsToComplete ¶
computes how many levels are needed to complete the pipeline in he version
func (*HENetwork) SetBox ¶
func (n *HENetwork) SetBox(box cipherUtils.CkksBox)
type HENetworkI ¶
type HENetworkI interface { //Rotations needed for inference. Also updates the box in the network with rotation keys GetRotations(params ckks.Parameters, btpParams *bootstrapping.Parameters) []int GetBox() cipherUtils.CkksBox SetBox(Box cipherUtils.CkksBox) //Evaluates batch. Treats each layer l as: Act[l](X * weight[l] + bias[l]) Eval(X cipherUtils.BlocksOperand) (*cipherUtils.EncInput, time.Duration) //Evaluates batch with debug statements. Needs the batch in clear and the network in cleartext. //Additionally needs the max L1 norm of the difference allowed for each intermediate result, elementwise. //If difference is > L1Thresh, it panics EvalDebug(Xenc cipherUtils.BlocksOperand, Xclear *mat.Dense, network NetworkI, L1thresh float64) (*cipherUtils.EncInput, *mat.Dense, time.Duration) //Checks if ciphertext at current level, for layer layer, needs bootstrap (true) or not //afterMul: if already multiplied by weight //forAct: if before activation CheckLvlAtLayer(level, minLevel, layer int, forAct, afterMul bool) bool //Returns number of levels requested to complete pipeline from current layer //afterMul: if already multiplied by weight LevelsToComplete(currLayer int, afterMul bool) int //True if network is initialized correctly IsInit() bool }
func NewHENetwork ¶
func NewHENetwork(network NetworkI, splits *cipherUtils.Split, encrypted, bootstrappable bool, maxLevel, minLevel, btpCapacity int, Bootstrapper cipherUtils.IBootstrapper, poolsize int, Box cipherUtils.CkksBox) HENetworkI
Creates a new network for he inference Needs splits of input and weights and loaded network from json
type Initiator ¶
type Initiator func(args ...interface{}) []utils.ChebyPolyApprox
initiator for activation functions. Must return a list of polynomials which approximate the activation function at each layer note that Identity activations functions are supported only at the end of the network (otherwise adjacent linear layers can be collapsed)
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network loaded from json. Implements INetwork. Abstract type
func (*Network) CheckLvlAtLayer ¶
True if bootstrap is needed
func (*Network) GetActivations ¶
func (n *Network) GetActivations() []utils.ChebyPolyApprox
func (*Network) GetDimentions ¶
Returns array of rows and cols of weights
func (*Network) GetNumOfActivations ¶
func (*Network) GetNumOfLayers ¶
func (*Network) GetParamsRescaled ¶
Gets weight and bias rescaled before activation (e.g for activation in Chebychev base)
func (*Network) LevelsToComplete ¶
Returns the levels needed to complete the pipeline from current layers, before or after the weigth multplication
func (*Network) NewHE ¶
func (n *Network) NewHE(splits *cipherUtils.Split, encrypted, bootstrappable bool, maxLevel, minLevel, btpCapacity int, Bootstrapper cipherUtils.IBootstrapper, poolsize int, Box cipherUtils.CkksBox) HENetworkI
func (*Network) SetActivations ¶
func (n *Network) SetActivations(activations []utils.ChebyPolyApprox)
type NetworkI ¶
type NetworkI interface { SetBatch(batchSize int) SetLayers(layers []utils.Layer) SetActivations(activations []utils.ChebyPolyApprox) //returns weights and biases GetParams() ([]*mat.Dense, []*mat.Dense) //returns weight and biases rescaled for approximated activation GetParamsRescaled() ([]*mat.Dense, []*mat.Dense) GetActivations() []utils.ChebyPolyApprox GetNumOfLayers() int GetNumOfActivations() int //gets rows and cols of weights as linear layers GetDimentions() ([]int, []int) //true if network is initialized, i.e if batch is defined as well as layers and activations IsInit() bool //true if he version needs bootstrapping at this layer with level = level CheckLvlAtLayer(level, minLevel, layer int, forAct, afterMul bool) bool //computes how many levels are needed to complete the pipeline in he version LevelsToComplete(currLayer int, afterMul bool) int //Creates the HE version of this network NewHE(splits *cipherUtils.Split, encrypted, bootstrappable bool, maxLevel, minLevel, btpCapacity int, Bootstrapper cipherUtils.IBootstrapper, poolsize int, Box cipherUtils.CkksBox) HENetworkI }
Network loaded from json
type NetworkJ ¶
type NetworkJ struct { Layers []utils.Layer `json:"layers,omitempty"` NumLayers int `json:"numLayers,omitempty"` }
NetworkJ wrapper for json struct
type NetworkLoader ¶
Custom Network Loader. Exposes the method Load to load model from file User should make sure that this method initiates also activation functions with a user-defined init method: this means that Load should return an initiliazed network, with the activations field populated by SetActivations. It is user responsability to provide and invoke an initiator method within Load The json structure should be compatible with Network