-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
On this page you will be shown a basic step by step how to do it, not being the only way to do it, just one of them, and finally more examples, as follows:
PyUDLF enables new ways to manage UDLF. But the right sequence of operations would be:
- Setting the file paths.
- Setting the values for the parameters.
- Execution.
- Results, if requested at execution.
But first you need to know how to execute them, just follow the step-by-step instructions below, note that the examples in each part complement each other, and at the end there is an example of a complete execution:
udlf requires the binary file and the configuration file to run. So in pyUDLF we have the variables "bin_path" and "config_path", available in the run_calls page, they store the complete paths to these mandatory files, however, if the user decides not to define these paths, they have as default value the system user path and on execution pyUDLF will check for them and if it doesn't find them, it will download them in this default path. If the path to the configuration file is set, the values that will be in the parameters of the inputType class will be those of this configuration file. So there are two ways to set these paths:
first: default settings
#User path
from pyUDLF import run_calls as udlf
default_bin_path = udlf.getBinaryPath()
default_config_path = udlf.getConfigPath()
print(default_bin_path)
print(default_config_path)
second: define them.
from pyUDLF import run_calls as udlf
# Caminhos de exemplo apenas
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
udlf.setConfigPath("/home/usr/Desktop/UDLF/UDLF/bin/config.ini")
bin_path = udlf.getBinaryPath()
config_path = udlf.getConfigPath
print(bin_path)
print(config_path)
# or
# print(udlf.bin_path)
# print(udlf.config_path)
To change parameter values, the class inputType has to be used. Remember, if the path to the config file was supplied, the parameter values of the input class object will be those of the file, otherwise they will have values from a default config. Once an object of this class is instantiated, the parameter modification is done through the functions "get" and "set", all available functions can be found in this link.
from pyUDLF import run_calls as udlf
from pyUDLF import inputType
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
udlf.setConfigPath("/home/usr/Desktop/UDLF/UDLF/bin/my_config.ini")
files_path = "../Soccer/matrices/distance/acc.txt"
classes_path = "/home/gustavo/Desktop/UDLF/UDLF/Soccer/classes.txt"
input_data.set_method_name("CPRR")
input_data.set_input_files(files_path)
input_data.set_lists_file(".../Soccer/lists.txt")
input_data.set_classes_file(classes_path)
...
#generic parameter
#set_param("param_name", param_value)
input_data.set_param("UDL_TASK", "UDL") #(UDL|FUSION): Selection of task to be executed
input_data.set_param("PARAM_NONE_L", 1400) #(TUint): Size of the ranked list (must be lesser than SIZE_DATASET)
Note that, the paths have been defined for exemplification. But defining the paths of an existing config brings advantages like not having to change, every time you run it, the minimum necessary parameters (class file, list file, ranked list,...). Besides that, it is worth remembering that some parameters only accept string values while others accept integer values.
After defining the paths and parameters, comes the execution part, where the functions for this can be found on the run_calls page. It can be done in two ways, and each one of them can be done requesting or not requesting the return, as follows:
- Without config: Through an object of class inputType, using the function "run", of run_calls, using this object as a parameter and if the result is requested.
from pyUDLF import run_calls as udlf
from pyUDLF import inputType
# NO RETURN
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
udlf.setConfigPath("/home/usr/Desktop/UDLF/UDLF/bin/minha_config.ini")
input_data = inputType.InputType()
udlf.run(input_data, get_output = False)
- With config: Through the "runWithConfig" function of [run_calls] you can run it passing as parameter the path to some existing config and if the result is requested.
from pyUDLF import run_calls as udlf
# NO RETURN
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
my_config_path = "/home/usr/Desktop/UDLF/UDLF/bin/minha_config.ini"
udlf.runWithConfig(my_config_path, get_output = False)
Note that in none of the above examples was the return requested. But if it was, an object of class output would be returned, more details are in part 4 below.
After the whole configuration and execution process, if return was requested, an object of the outputType class will be returned. This class contains functions to display and/or return the log, return the matrix or the ranked list depending on the execution. Moreover, the log is a dictionary type variable that contains the execution information, for example the "MAP", the execution time, here follows an example of the "log":
Time = 0.0061 s
P@4 = {'Before': '0.6518', 'After': '0.7000', 'Gain': '7.3973%'}
P@5 = {'Before': '0.6136', 'After': '0.6671', 'Gain': '8.7311%'}
P@10 = {'Before': '0.5146', 'After': '0.5896', 'Gain': '14.5732%'}
P@15 = {'Before': '0.4650', 'After': '0.5479', 'Gain': '17.8187%'}
P@20 = {'Before': '0.4346', 'After': '0.5130', 'Gain': '18.0362%'}
P@30 = {'Before': '0.3840', 'After': '0.4675', 'Gain': '21.7297%'}
P@50 = {'Before': '0.3241', 'After': '0.4028', 'Gain': '24.2618%'}
P@100 = {'Before': '0.2466', 'After': '0.2875', 'Gain': '16.5991%'}
Recall@4 = {'Before': '0.0652', 'After': '0.0700', 'Gain': '7.3972%'}
Recall@5 = {'Before': '0.0767', 'After': '0.0834', 'Gain': '8.7311%'}
Recall@10 = {'Before': '0.1287', 'After': '0.1474', 'Gain': '14.5732%'}
Recall@20 = {'Before': '0.2173', 'After': '0.2565', 'Gain': '18.0362%'}
Recall@40 = {'Before': '0.3500', 'After': '0.4354', 'Gain': '24.4133%'}
MAP = {'Before': '0.3725', 'After': '0.4718', 'Gain': '26.6584%'}
To request this, simply pass the parameter "get_output" as true in the functions "run" or "runWithConfig", depending on the type of execution. Here is an example of a run without config with return:
from pyUDLF import run_calls as udlf
from pyUDLF import inputType
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
udlf.setConfigPath = ("/home/usr/Desktop/UDLF/UDLF/bin/minha_config.ini")
input_data = inputType.InputType()
output = udlf.run(input_data, get_output = True)
output.print_log()
After the return values are requested, an object of class outputType is returned, which has functions to display and return the log and return the matrix or ranked list, depending on the type of execution, these functions are in this link.
Finally a complete example of a run of the type without config, changing some parameters and requesting the return:
from pyUDLF import run_calls as udlf
from pyUDLF import inputType
# 1) Defining the paths to the binary and configuration file
udlf.setBinaryPath("/home/usr/Desktop/UDLF/UDLF/bin/udlf")
udlf.setConfigPath("/home/usr/Desktop/UDLF/UDLF/bin/minha_config.ini")
# 2) Set functions examples
files_path = "../Soccer/matrices/distance/acc.txt"
classes_path = "/home/gustavo/Desktop/UDLF/UDLF/Soccer/classes.txt"
input_data = inputType.InputType()
input_data.set_param("UDL_TASK", "UDL")
input_data.set_param("PARAM_NONE_L", 1400)
input_data.set_method_name("CPRR")
input_data.set_param("PARAM_CPRR_L", 280)
input_data.set_method_name("CPRR")
input_data.set_input_files(files_path)
input_data.set_lists_file(".../Soccer/lists.txt")
input_data.set_classes_file(classes_path)
...
# Get functions examples
method = input_data.get_method_name()
size = input_data.get_dataset_size()
list_path = get_lists_file()
...
# 3) Execution example
output = udlf.run(input_data, get_output = True)
# 4) Return example
output.print_log()
return_values = get_log()
map = return_values["MAP"]["After"] # or ["Before"] or ["Gain"]
map2 = return_values["MAP"]
time = resuturn_values["Time"]
output.print_log()
print(map)
print(map2)
print(time)
In this part you can find more examples of many different types, from the most complex to the most basic, such as other forms of operation. Just access the link below:
The examples listed here are those used to exemplify the pyUDLF functions. If you have done something different, feel free to contribute to the community.