What does JaCoCo rule elements mean and how to combine them - jacoco

I'm trying to understand JaCoCo rules but there are not many great examples around. Every thread I see circulates the same examples from the docs.
I see 3 different metrics:
element types (BUNDLE, PACKAGE, CLASS, SOURCEFILE or METHOD)
limits (INSTRUCTION, LINE, BRANCH, COMPLEXITY, METHOD, CLASS)
values (TOTALCOUNT, COVEREDCOUNT, MISSEDCOUNT, COVEREDRATIO, MISSEDRATIO)
I understand that "element types" represent the scope of each rule, fair enough.
BUNDLE: That represents the project as a whole
PACKAGE: Each java package
CLASS: As name states, a single class
SOURCEFILE: How is this different than the CLASS? Does this have to do with inner classes?
METHOD: Scope is for each method
Now though, how limits and values come into scope? For example:
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
can I replace LINE with INSTRUCTION for example? And if yes, what does this mean?
Also from the docs:
If a limit refers to a ratio it must be in the range from 0.0 to 1.0 where the number of decimal places will also determine the precision in error messages.
RATIO vs COUNT is clear, but can I use them interchangeably? i.e:
<limit>
<counter>LINE</counter>
<value>TOTALCOUNT</value>
<minimum>3</minimum>
</limit>
and if yes, what does the above rule mean?
From a generated report, INSTRUCTION and BRANCH are always on ratio

So, a part of this question regarding BUNDLE, SOURCEFILE, and CLASS just got answered here in the JaCoCo groups.
Essentially,
BUNDLE - All classes in the Maven module combined together will be checked against the rule
SOURCEFILE - Each Java file will be checked against the rule
CLASS - Each Class file will be checked against the rule
The confusion starts for SOURCEFILE and CLASS, but you need to understand that a Java file can have multiple classes. For example, here is Shape.java which has 2 classes - Shape and Triangle.
public abstract class Shape {
}
class Triangle extends Shape {
}
SOURCEFILE will check the rules against Shape.java, while CLASS with check the rule against both Shape and Triangle.
For instance, here is a rule configuration
<rule>
<element>SOURCEFILE</element><!-- Here I change it for SOURCEFILE and CLASS values -->
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>TOTALCOUNT</value>
<maximum>1</maximum>
</limit>
</limits>
</rule>
Below is the output for SOURCEFILE config.
[WARNING] Rule violated for source file io/codejournal/maven/jacocodemo/Shape.java: instructions total count is 6, but expected maximum is 1
When you run the same thing with CLASS config, the output is for each class separately.
[WARNING] Rule violated for class io.codejournal.maven.jacocodemo.Triangle: instructions total count is 3, but expected maximum is 1
[WARNING] Rule violated for class io.codejournal.maven.jacocodemo.Shape: instructions total count is 3, but expected maximum is 1

Related

Object labels "from 0 to num_classes-1" or from "1 to num_classes" in built in image object detection on Google Cloud?

The Google built-in object detection documentation/reference says the the num_classes argument should be set as follows:
E.g., for num_classes=5, the range of image/class/label in input tf.Example needs to be [0, 4].
Yet, most other resources (e.g., here) on how to create your own dataset in the object detection API world say that labels should start with 1, that is, for 5 classes they should be [1,5].
My questions are:
Is the example in the reference documentation correct, that is, should I use [0,4] for 5 classes?
Does it matter at all, i.e., can this break the training procedure?
Is the "built-in object detection" algorithm special in other ways or can I follow the "using your own dataset" function to create my TFrecord files?
Seems like the labels should be [1,5].
The documentation has changed :)
See the updated documnetation
under --> Hyperparameters --> num_classes

Why does dlib's neural net xml export contain different parameters for layers than specified by the trainer?

In DLib it is possible to simply output a neural net type via the dlib::net_to_xml(some_net, some_filename) function. It works fine, but it also displays information like for example the net type, learning_rate_multi. In my case for example it exports the following line for one of the layers (the rest of the exported xml is omitted for clarity):
<fc num_outputs='42' learning_rate_mult='1' weight_decay_mult='1' bias_learning_rate_mult='500' bias_weight_decay_mult='0'>
Those values are correct, except for learning_rate_mult and weight_decay_mult, which always show 1. I tried setting them to different values with the trainer class, like 2 or 0.0001, but they keep showing 1. I verified that the values 2 and 0.0001 indeed were used by the net.
Might this be a bug in dlib's dlib::net_to:xml function?
Those values apply for every layer and are independent from the trainer-values. The layer parameters are relevant for optimzers like the Adam Optimization Algorithm:
https://machinelearningmastery.com/adam-optimization-algorithm-for-deep-learning/
you can change them by specifyng them in every layer.
So no it is not a bug.

Accessing constraints/objective

I'm using a toolbox that internally calls Pyomo to solve an optimization problem. I am interested in accessing the Pyomo model it constructs so I can modify the constraints/objective. So my question is, suppose I get the following output:
Problem:
Name: unknown
Lower bound: 6250.0
Upper bound: 6250.0
Number of objectives: 1
Number of constraints: 11
Number of variables: 8
Number of nonzeros: 17
Sense: minimize
Solver:
Status: ok
Termination condition: optimal
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Error rc: 0
Time: 0.015599727630615234
Solution:
number of solutions: 0
number of solutions displayed: 0
So the problem works well and I get a solution, the modeling was done internally via another too. Is it possible to access the constraints/objective so I can freely modify the optimization model in Pyomo syntax?
I tried to call the model and got something like this:
<pyomo.core.base.PyomoModel.ConcreteModel at xxxxxxx>
It sounds like network.model is the Pyomo model and yes, if you have access to it, you can modify it. Try printing the model or individual model components using the pprint() method:
network.model.pprint()
network.model.con1.pprint()
or you can loop over specific types of components in the model:
for c in network.model.component_objects(Constraint):
print(c) # Prints the name of every constraint on the model
The easiest way to modify the objective would be to find the existing one, deactivate it, and add a new one
network.model.obj.deactivate()
network.model.new_obj = Objective(expr=network.model.x**2)
There are ways to modify constraints/objectives in place but they are not well-documented. I'd recommend using Python's dir() function and playing around with some of the component attributes and methods to get a feel for how they work.
dir(network.model.obj)

What is the syntax to be used for feed_dict in TensorFlow C++?

I want to build and train a graph in TensorFlow C++ that consists of two layers, and to feed it with a given matrix as an input.
I have two different examples for the syntax:
The official C++ example (line # 129)
An old answer in StackOverflow
It seems they contradict each other with respect to the exact syntax of the "input" parameter to tensorflow::Session::Run()
Should it be "placeholder_name:0" or "placeholder_name"?
Either one works. The name gets passed through ParseTensorName, where names without a colon are assumed to have an output index of 0. To verify this, we can add a ":0" to the end of the feed name in DirectSessionMinusAXTest::TestFeed:
std::vector<std::pair<string, Tensor>> inputs = {{x_, t}};
becomes
std::vector<std::pair<string, Tensor>> inputs = {{x_ + ":0", t}};
and it still passes.
The only case where passing an output index is required (more accurately the only case where it should be required; there may be some code lacking canonicalization) is if you're feeding a Tensor which is not the zeroth output of an operation (e.g. "unique:1"). This is quite rare, since constant and placeholder ops are the most likely feed targets and only have a single output.

Weka - no class and no cluster assign

I am working on a file to predict treatment ways for patients diagnosed with diabetes (level is from 1 to 10).
There are 8 different treatment recommendations (256 possible outcome) and I need to cluster them (I have 21 attributes from the original file.). So I used 19 k with SimpleKMean. The problem is I get "no class" assigned for some clusters;
Also when I classify it for evaluation, I have the same problem "no cluster" assigned to class and also I lose some of the data. For example there are 940 instances but I have 876 after classifying.
But the confusion matrix displays the exact numbers. I don't know if it is related but it might help to solve the question. I have used AddCluster method because all my attribute are numeric and I need an additional column from the original file in order to display "Treatment Cluster" (22th attribute). So I run SimpleKMean and Cross-Validation with this new additional attribute which is also my class.
Thanks a lot for your help!!!
It appears that a class can only be applied to zero or one clusters. As a result, for example, class 9 is being applied to cluster 7, but all of the class 9 values in cluster 8 is not being assigned as it was being allocated to another class. The SimpleKMeans model appears to assign the cluster that generates the minimum classification error on the supplied data.
This problem has been raised before here, where the solution appears to be overriding the evaluation model to allow for one-to-many allocations.