Example #1
0
def query(network_file, params_file="", resultsdir=""):
    '''
    :param network_file: a .txt file containing either a single DSGRN network specification or a list of network specification strings in DSGRN format
    :param params_file: A json file with the key
            "count" = True or False (true or false in .json format)
                        whether or not to return the number of matches (True) or just whether or not there is at least one match (False)
            "datetime" : optional datetime string to append to subdirectories in resultsdir, default = system time
    :param resultsdir: optional path to directory where results will be written, default is current directory

    :return:  Writes a .json file containing a dictionary keyed by DSGRN network specification with a list of results.
            The results are DSGRN parameter count that have at least one Morse set that is a stable full cycle,
            or True (existence of at least one stable full cycle) or False (none exist), depending on the value of the parameter "count".
            The size of the DSGRN parameter graph for the network is also recorded.
            { networkspec : [result, DSGRN param graph size] }.
    '''

    networks = read_networks(network_file)
    params = json.load(open(params_file))
    datetime = None if "datetime" not in params else params["datetime"]

    if not networks:
        raise ValueError(
            "No networks available for analysis. Make sure network file is in the correct format."
        )
    else:
        count = sanity_check(params)
        work_function = partial(search_over_networks, count, len(networks))
        with MPICommExecutor(MPI.COMM_WORLD, root=0) as executor:
            if executor is not None:
                print("Querying networks.")
                output = list(executor.map(work_function, enumerate(networks)))
                results = dict(output)
                record_results(network_file, params_file, results, resultsdir,
                               datetime)
Example #2
0
def query(network_file, params_file, resultsdir=""):
    '''
    Take the intersection of an arbitrary number of DSGRN fixed points in a list.

    :param network_file: a .txt file containing either a single DSGRN network specification or
                a list of network specification strings in DSGRN format
    :param params_file: A json file with a dictionary containing the keys
                    "included_bounds", "excluded_bounds", and "count".
                    The two "bounds" variables are each a list of dictionaries of variable names common to all network
                    specifications with an associated integer range.
                    Example: [{"X1":[2,2],"X2":[1,1],"X3":[0,1]},{"X1":[0,1],"X2":[1,1],"X3":[2,3]}]
                    The integer ranges are the matching conditions for an FP.
                    For example, if there are four variables X1, X2, X3, X4 in the network spec,
                    the FP (2,1,0,*) would be a match to the first fixed point for any value of *.
                    The "included_bounds" are those fixed points that must be present and
                    the "excluded_bounds" are those that must be absent. Either one or both may be empty. When they are both empty,
                    the count is just the number of parameters with at least one fixed point.
                    "count" : True or False (true or false in .json format);
                    whether to count all parameters with a match or shortcut at first success
                    "datetime" : optional datetime string to append to subdirectories in resultsdir, default = system time
                    "neighbors" : optional True or False (true or false in .json format) stating whether to query DSGRN parameters that
                    neighbor essential DSGRN parameters, neighbor-checking is computationally expensive, default = False

    :param resultsdir: optional path to directory where results will be written, default is current directory

    :return: Writes a .json file containing a dictionary keyed by DSGRN network specification with a list of results.
            The results are DSGRN parameter count with successful matches to the fixed point bounds, or True
            (existence of at least one match) or False (no matches exist), depending on the value of the parameter "count".
            The size of the DSGRN parameter graph for the network is also recorded.
            { networkspec : [result, DSGRN param graph size] }.
            If "hex_constraints" are specified, then the number of DSGRN parameters that satsify those hex constraints
            (with or without a bounds match) are also recorded.
            { networkspec : [result, num params with hex constraints, DSGRN param graph size] }.
    '''

    networks = read_networks(network_file)
    params = json.load(open(params_file))
    datetime = None if "datetime" not in params else params["datetime"]

    sanity_check(params)

    if not networks:
        raise ValueError(
            "No networks available for analysis. Make sure network file is in the correct format."
        )
    else:
        work_function = partial(search_over_networks, params, len(networks))
        with MPICommExecutor(MPI.COMM_WORLD, root=0) as executor:
            if executor is not None:
                print("Querying networks.")
                output = list(executor.map(work_function, enumerate(networks)))
                results = dict(output)
                record_results(network_file, params_file, results, resultsdir,
                               datetime)
def query(network_file, params_file, resultsdir=""):
    '''
    For each epsilon in a list of epsilons, a partially ordered set (poset) of maxima and minima of time series data
    is created or accessed from the params dictionary.
    This poset is matched against the domain graph for each DSGRN parameter for each network in a list of networks.
    The result is the count of the number of DSGRN parameters with a match OR is True if there is at least one match
    and False if not, depending on the choice of the parameter "count".

    :param network_file: a .txt file containing a single DSGRN network specification
    specification strings in DSGRN format
    :param params_file: A .json file containing a dictionary with the keys
        "domain" : True or False (true or false in .json format), whether or not to perform a path search anywhere in the domain graph
        "stablefc" : True or False (true or false in .json format), whether or not to perform a path search within stable full cycles
        Both "domain" and "stablefc" are allowed to be True.
        "count" : True or False (true or false in .json format), whether to count all DSGRN parameters or shortcut at first success
            NOTE: Only count = True is currently implemented
        "datetime" : optional datetime string to append to subdirectories in resultsdir, default = system time
        "parameter_list" : optional sublist of the parameter graph

        One can either specify posets directly, or extract posets from timeseries data.
        Include EITHER the three keys
        "timeseriesfname" : path to a file or list of files containing the time series data from which to make posets
        "tsfile_is_row_format" : True if the time series file is in row format (times are in the first row); False if in
        column format (times are in the first column)
        "epsilons" : list of floats 0 <= x <= 0.5, one poset will be made for each x
                    Note that an epsilon of 0.10 means that the noise level is considered to be +/- 10% of the distance
                    between global maximum and global minimum for each time series. Thus all information on curve shape
                    is lost at epsilon = 0.5. It is recommended to stay below that level.
        OR the single key
        "posets" : a (quoted) dictionary of Python tuples of node names keying a list of tuples of epsilon with a DSGRN
        formatted poset:
                    '{ ("A","B","C") : [(eps11,poset11), (eps21,poset21),...], ("A","B","D") : [(eps12,poset12), (eps22,
                    poset22),...] }' (the quotes are to handle difficulties with the json format)
        This key takes specialized information and is not likely to be specified in general usage.

    :param resultsdir: optional path to directory where results will be written, default is current directory

    :return: Writes a .json file containing a dictionary keyed by DSGRN network specification with a list of results.
        The results are DSGRN parameter count with successful matches, or True (existence of at least one match)
        or False (no pattern matches exist), depending on the value of the parameter "count". The size of the DSGRN
        parameter graph for the network and the value of 'epsilon' for the attempted match to the time series are
        also recorded.
        { networkspec : [(eps, result, DSGRN param graph size)] }.
        When "stablefc" and "count" are both True, the number of stable full cycles (with or without a pattern match)
        is also recorded:
        { networkspec : [(eps, result, num stable full cycles, DSGRN param graph size)] }

        Separate files will be written for "domain", "stablefc", and each timeseries file name.
        When multiple time series are specified and "count" is True, a file with the string "all" in the name will be
        written with the aggregated results across time series datasets (this eliminates the double-counting of DSGRN
        parameters that can occur across multiple time series). The file ending in "all" records the number of DSGRN
        parameters with a match to at least one time series dataset.
    '''

    spec = read_networks(network_file)
    print(spec)
    param_dict = json.load(open(params_file))

    sanity_check(param_dict)

    posets, networks = get_posets(spec, param_dict)
    print("Querying networks.\n")

    if not networks:
        print(
            "No networks available for analysis. Make sure network file is in the correct format\nand make sure that every network node name is the time series data or 'poset' value."
        )
        return None
    else:
        results = {}
        if param_dict["count"]:
            with MPICommExecutor() as executor:
                spec = spec[0]
                results[spec] = {}
                network = DSGRN.Network(spec)
                param_graph = DSGRN.ParameterGraph(network)
                if "parameter_list" in param_dict:
                    dsgrn_params = [(p, param_graph.parameter(p))
                                    for p in param_dict["parameter_list"]]
                else:
                    dsgrn_params = [(p, param_graph.parameter(p))
                                    for p in range(param_graph.size())]
                names = tuple(
                    sorted([network.name(k) for k in range(network.size())]))
                work_function = partial(PathMatch, network, posets[names],
                                        param_dict["domain"],
                                        param_dict["stablefc"])
                output = dict(executor.map(work_function, dsgrn_params))
                results[spec] = reformat_output(output,
                                                list(posets[names].keys()),
                                                param_dict, param_graph.size())
                print("Network {} of {} complete.".format(1, 1))
                sys.stdout.flush()
                record_results(network_file, params_file, results, resultsdir,
                               param_dict)
        else:
            raise ValueError(
                "Existence of path match without counting is not yet implemented for large networks. Use CountPatternMatch.py."
            )
Example #4
0
def query(network_file, params_file, resultsdir=""):
    '''
    For each epsilon in a list of epsilons, a partially ordered set (poset) of maxima and minima of time series data
    is created or accessed from the params dictionary.
    This poset is matched against the domain graph for each DSGRN parameter for each network in a list of networks.
    The result is the count of the number of DSGRN parameters with a match OR is True if there is at least one match
    and False if not, depending on the choice of the parameter "count".

    :param network_file: a .txt file containing either a single DSGRN network specification or a list of network
    specification strings in DSGRN format
    :param params_file: A .json file containing a dictionary with the keys
        "domain" : True or False (true or false in .json format), whether or not to perform a path search anywhere in the domain graph
        "stablefc" : True or False (true or false in .json format), whether or not to perform a path search within stable full cycles
        Both "domain" and "stablefc" are allowed to be True.
        "count" : True or False (true or false in .json format), whether to count all DSGRN parameters or shortcut at first success
        "datetime" : optional datetime string to append to subdirectories in resultsdir, default = system time

        One can either specify posets directly, or extract posets from timeseries data.
        Include EITHER the three keys
        "timeseriesfname" : path to a file or list of files containing the time series data from which to make posets
        "tsfile_is_row_format" : True if the time series file is in row format (times are in the first row); False if in
        column format (times are in the first column)
        "epsilons" : list of floats 0 <= x <= 0.5, one poset will be made for each x
                    Note that an epsilon of 0.10 means that the noise level is considered to be +/- 10% of the distance
                    between global maximum and global minimum for each time series. Thus all information on curve shape
                    is lost at epsilon = 0.5. It is recommended to stay below that level.
        OR the single key
        "posets" : a (quoted) dictionary of Python tuples of node names keying a list of tuples of epsilon with a DSGRN
        formatted poset:
                    '{ ("A","B","C") : [(eps11,poset11), (eps21,poset21),...], ("A","B","D") : [(eps12,poset12), (eps22,
                    poset22),...] }' (the quotes are to handle difficulties with the json format)
        This key takes specialized information and is not likely to be specified in general usage.

    :param resultsdir: optional path to directory where results will be written, default is current directory

    :return: Writes a .json file containing a dictionary keyed by DSGRN network specification with a list of results.
        The results are DSGRN parameter count with successful matches, or True (existence of at least one match)
        or False (no pattern matches exist), depending on the value of the parameter "count". The size of the DSGRN
        parameter graph for the network and the value of 'epsilon' for the attempted match to the time series are
        also recorded.
        { networkspec : [(eps, result, DSGRN param graph size)] }.
        When "stablefc" and "count" are both True, the number of stable full cycles (with or without a pattern match)
        is also recorded:
        { networkspec : [(eps, result, num stable full cycles, DSGRN param graph size)] }

        Separate files will be written for "domain", "stablefc", and each timeseries file name.
        When multiple time series are specified and "count" is True, a file with the string "all" in the name will be
        written with the aggregated results across time series datasets (this eliminates the double-counting of DSGRN
        parameters that can occur across multiple time series). The file ending in "all" records the number of DSGRN
        parameters with a match to at least one time series dataset.
    '''

    networks = read_networks(network_file)
    params = json.load(open(params_file))

    sanity_check(params)

    posets, networks = get_posets(networks, params)

    if not networks:
        print(
            "No networks available for analysis. Make sure network file is in the correct format\nand make sure that every network node name is the time series data or 'poset' value."
        )
        return None
    else:
        work_function = partial(search_over_networks, params, posets,
                                len(networks))
        with MPICommExecutor(MPI.COMM_WORLD, root=0) as executor:
            if executor is not None:
                print("Querying networks.")
                output = list(executor.map(work_function, enumerate(networks)))
                results = dict(output)
                record_results(network_file, params_file, results, resultsdir,
                               params)