Example #1
0
def _findConstant(savePath):
    pathForDeterminingConstant = os.path.join(savePath,
                                              "toDefineModelConstant")

    # Let us determine the constant that goes with the chemical model, by simply defining a small network.
    smallMasks = [np.array([[1, -1]])]
    complexity = "simple"
    useProtectionOnActivator = False
    useEndoOnOutputs = True
    useEndoOnInputs = False
    generateTemplateNeuralNetwork(
        pathForDeterminingConstant,
        smallMasks,
        complexity=complexity,
        useProtectionOnActivator=useProtectionOnActivator,
        useEndoOnOutputs=useEndoOnOutputs,
        useEndoOnInputs=useEndoOnInputs)
    parsedEquation, constants, nameDic = read_file(
        pathForDeterminingConstant + "/equations.txt",
        pathForDeterminingConstant + "/constants.txt")
    KarrayA, stochio, maskA, maskComplementary = sparseParser(
        parsedEquation, constants)
    _, T0, C0, _ = setToUnits(constants, KarrayA, stochio)
    constantList = [
        0.9999999999999998, 0.1764705882352941, 1.0, 0.9999999999999998,
        0.1764705882352941, 1.0, 0.9999999999999998, 0.1764705882352941, 1.0,
        0.018823529411764708
    ]
    constantList += [constantList[-1]]
    enzymeInit = 5 * 10**(-7) / C0
    activInit = 10**(-4) / C0
    inhibInit = 10**(-4) / C0
    return constantList, enzymeInit, activInit, inhibInit, C0
Example #2
0
def load(directory_name="weightDir",
         directory_for_network="",
         useEndo=False,
         complexity="simple",
         useProtectionOnActivator=False,
         useEndoOnOutputs=True,
         useEndoOnInputs=False):
    """
        Generate the biochemical equations from the weights of a deep neural network.
        The weights should be stored in the format csv, with the following name:
            weight_LayerNb
        The weight dir should be a directory containing only weights files.
        Bias should not be given in this file as we ignore it in the current algorithm.
    """
    files = os.listdir(directory_name)
    files = np.sort(files)

    # Load the masks:
    # We use 0.2 to discriminate the clipping values, as was done during training and validation
    masks = []
    for file in files:
        if (file.split("_")[0] == "weight"):
            df = pandas.read_csv(os.path.join(directory_name, file))
            W = np.transpose(df.values[:, 1:])
            WZeros = np.zeros((W.shape))
            WPos = np.zeros((W.shape)) + 1
            WNeg = np.zeros((W.shape)) + -1
            masks += [
                np.where(W < -0.2, WNeg, np.where(W > 0.2, WPos, WZeros))
            ]

    # We generate the chemical network
    # For constants we can either let the default value or give pre-defined values, for now use default value
    if useEndo:
        generateTemplateNeuralNetwork(
            directory_for_network,
            masks,
            complexity=complexity,
            useProtectionOnActivator=useProtectionOnActivator,
            useEndoOnOutputs=useEndoOnOutputs,
            useEndoOnInputs=useEndoOnInputs)
    else:
        generateTemplateNeuralNetwork(
            directory_for_network,
            masks,
            complexity=complexity,
            endoConstants=None,
            useProtectionOnActivator=useProtectionOnActivator,
            useEndoOnInputs=useEndoOnInputs,
            useEndoOnOutputs=useEndoOnOutputs)
    print("Generated network at " + str(directory_for_network))
    return directory_for_network, masks
    useDerivativeLeak = True

    leak = 10**(-10)

    layerInit = 10**(-13)  #initial concentation value for species in layers
    initValue = 10**(-13)  #initial concentration value for all species.
    enzymeInit = 5 * 10**(-7)
    endoInit = 10**(-5)  #only used if useEndo == True
    activInit = 10**(-4)
    inhibInit = 10**(-4)

    if useEndo:
        generateTemplateNeuralNetwork(
            name,
            masks,
            complexity=complexity,
            useProtectionOnActivator=useProtectionOnActivator,
            useEndoOnOutputs=useEndoOnOutputs,
            useEndoOnInputs=useEndoOnInputs)
    else:
        generateTemplateNeuralNetwork(
            name,
            masks,
            complexity=complexity,
            endoConstants=None,
            useProtectionOnActivator=useProtectionOnActivator,
            useEndoOnInputs=useEndoOnInputs,
            useEndoOnOutputs=useEndoOnOutputs)

    X1, X2, x_test, otherActivInitialC, otherInhibInitialC = _generate_initialConcentration_firstlayer(
        activatorsOnObserved,