I want to show use of same algorithm as a black box in two-pass iteration. In first pass, I would pass a value of a flag f as false, and an array of one element as A[1..1], output of first pass would be B[1..N]. In second pass, same algorithm would be used with f as true (to indicate second pass) with an input of A[1..N] (fed from output B[1..N] of first pass) whereas the output of second pass would be B[1..M]
Please help me drawing the UML Activity diagram for the same.
It's not a good idea to try "programming graphically". The algorithm you describe is better shown in meta code than in an activity diagram, as you already have seen. So what I'd do in your case is to have a single Action (representing most likely some CallOperation of some class. And the according behavior of the operation contains the description in either meta code or plain text (as you already stated above).
If for what reason ever you really want to "program graphically" you would need to use single actions for the assignments of the flag like this:
The A and B arrays would be just mentioned in the description of the single actions.
To actually show passing the A and B arrays you would need to add ActionsPins or Objects with ObjectFlows between the single Actions. Honestly, that would make the whole thing even more unreadable and hinder more than helping the reader:
Related
i've this method findNegozio(insertID) used to find the element with insertID in a Collection.
So, findNegozio(insertID) is an operation that is often referred to in my sequence diagrams so I thought I would illustrate it as a sequence diagram.
The idea is to represent an iteration on a collection and take only the element that matches with the entered ID.
Could this be a good way to represent my idea?
is it useful to represent a frequent step of some sequence diagrams?
EDIT: Maybe with only one step is better OPT instead of ALT.
First three remarks :
For me your code is invalid because a return is missing after the loop => I suppose a variable result is added and initialized to null, set to the found item if exist, and finally used for a final return.
Are you sure findNegocio is not static ?
Why findNegocio is defined on Negocio and not on GestoreNegocio ?
A sequence diagram shows an interaction (partially or not) and focuses on message interchange between lifelines.
From the definition of your operation it is needed to decide whose messages are enough interesting to be shown in your sequence diagram. I don't think the details concerning the list and iterator have to be shown, they are very classical, the goal is not to explain how to work with Java builtin classes.
To break the loop you have the fragment break, so your sequence diagram can be (I added a caller because my tool does not manage lost/found messages) :
But perhaps the main information shown is the use of GestoreNegocio and the loop by itself is not really interesting ?
I am trying to implement the ID3 algorithm, and am looking at the pseudo-code:
(Source)
I am confused by the bit where it says:
If examples_vi is empty, create a leaf node with label = most common value in TargegetAttribute in Examples.
Unless I am missing out on something, shouldn't this be the most common class?
That is, if we cannot split the data on an attribute value because no sample takes that value for the particular attribute, then we take the most common class among all samples and use that?
Also, isn't this just as good as picking a random class?
The training set tells us nothing about the relation between the attribute value and the class labels...
1) Unless I am missing out on something, shouldn't this be the most
common class?
You're correct, and the text also says the same. Look at the function description at the top :
Target_Attribute is the attribute whose value is to be predicted by the tree
so the value of Target_Attribute is the class/label.
2) That is, if we cannot split the data on an attribute value because no sample takes that value for the particular attribute, then we take the most common class among all samples and use that?
Yes, but not among all samples in your whole dataset, but rather those samples that reached up to this point in the tree/recursion. (ID3 functions is recursive and so the current Examples is actually Examples_vi of the caller)
3) Also, isn't this just as good as picking a random class?
The training set tells us nothing about the relation between the attribute value and the class labels...
No, picking a random class (with equal chances for each class) is not the same. Because often the inputs do have an unbalanced class distribution (this distribution is often called the prior distribution in many texts), so you may have 99% of examples are positive and only 1% negative. So whenever you really have no information whatsoever to decide on the outcome of some input, it makes sense to predict the most probable class, so that you have the most probability of being correct. This maximizes your classifier's accuracy on unseen data only under the assumption that the class distribution in your training data is the same as in the unseen data.
This explanation holds with the same reasoning for the base case when Attributes is empty (see 4 line in your pseudocode text); whenever we have no information, we just report the most common class of the data at hand.
If you never implemented the codes(ID3) but still want to know more in processing details, I suggest you to read this paper:
Building Decision Trees in Python
and here is the source code from the paper:
decision tree source code
This paper has a example or use example from your book(replace the "data" file with the same format). And you can just debug it (with some breakpoints) in eclipse to check the attribute values during the algorithms running.
Go over it, you will understand ID3 better.
Intro
When designing UML activity diagrams I often encounter a rather simple problem for which I have to draw a rather complicated solution. I'm looking for an UML conform shortcut or more simple solution for the following problem.
Problem
Lets assume we have a class Parent with associations to different Children:
And we have an analog Constalation with the class Result and three chidren Result Part A, etc.
Now I want to refine an activity, which accepts a Parent object as input and produces an Result as output:
In the desired refinement, I want to I want to access the children or create the result from the result parts.
Current Solution
If I want to access the children or create the result from the result parts, I always have to introduce extra activities for those rather simple tasks:
Question
Are there any shortcut or simplification here, to access, extract or merge the children of an object? The desired Solution should be legal standard UML.
Something as simple like this would be nice:
UML does not define complex object creation element. If you need to construct result object which is composition of child objects, you have to present action. You should define action with resulting pin of composed type and input pins of child object types for each one. Action can start execution only if all input pins contain expected object.
For separation of child object from composed object use transformation as it is described in Waog's answer.
In your current solution example remove join element before merge result Children action, and connect all object nodes to this action. Remove extract input Children action and use transformation.
Answer on how to split objects
I found an answer on how to split a composed object in Martin Fowlers UML distilled myself, after getting a hint from #xmojmr
The book states:
Source: UML Distilled: A Brief Guide to the Standard Object Modeling Language
By Martin Fowler - on Google Books
I still don't know, if it's allowed to omit thos transformation-notes and just draw the pins and transitions!?
Missing Answer on how to merge objects
I'm still missing the answer on how to merge objects to a composed objects without introducting a merge-activity.
I would like to know a bit more about the bounding this error relates to.
I have an alloy model for which I create an instance manually (by writting it down in XML).
This instance is readable and the A4Solution can be correctly displayed.
But when I try to evaluate an expression in this instance using the eval() function, I receive this error message, though the field name and type of the exprvar retrieved from the model is exactly the same as the one in the instance..
I would like to know what does this bounding consist of. What are the properties taken into consideration to tell that one element of the instance is bounded to one element of the model.
Is the hidden ID figuring in the XML somewhere taken into consideration ?
I would like to know what does this bounding consist of.
It means that every free variable (i.e., relation in Kodkod) has to be given a bound before asking the solver to solve the formula.
What are the properties taken into consideration to tell that one element of the instance is bounded to one element of the model.
The instance XML file contains and exact value (a tuple set) for each and every sig and field from the model; those tuple sets are exactly the bounds that should be used when evaluating expressions. I'm not sure how exactly you are trying to use the Alloy API; but recreating the bounds from the XML file should (mostly) be handled by the API behind the scene.
Judging by your last comment to my previous answer, your problem might be related to this post.
In a nutshell, if you are trying to evaluate AST expression objects obtained from one "alloy world" (CompModule) against a solution that was entirely recreated from an XML file, you will get exactly that error. For example, if you have two PrimSig objects, s1 and s2, and they both have the same name (e.g., both were obtained by parsing sig S {...}), they are not "Java equals" (s1.equals(s2) returns false); the same holds for the underlying Kodkod relations/variables. So if you then try to evaluate s1 in a context which has a bound only for s2, you'll get an error saying that s1 is not bound.
Providing the set of Signatures defined in the metamodel while reading the A4Solution solved my problem.
Thus changing:
solution = A4SolutionReader.read(null, new XMLNode(f));
by
solution = A4SolutionReader.read(mm.getAllReachableSigs(), new XMLNode(f));
solved this illegal bounding issue
I am receiving as input a "map" represented by strings, where certain nodes of the map have significance (s). For example:
---s--
--s---
s---s-
s---s-
-----s
My question is, what reasonable options are there for representing this input as an object.
The only option that really comes to mind is:
(1) Each position translated to node with up,down,left,right pointers. The whole object contains a pointer to top right node.
This seems like just a graph representation specific to this problem.
Thanks for the help.
Additionally, if there are common terms for this type of input, please let me know
Well, it depends a lot on what you need to delegate to those objects. OOP is basically about asking objects to perform things in order to solve a given problem, so it is hard to tell without knowing what you need to accomplish.
The solution you mention can be a valid one, as can also be having a matrix (in this case of 6x5) where you store in each matrix cell an object representing the node (just as an example, I used both approaches once to model the Conway's game of life). If you could give some more information on what you need to do with the object representation of your map then a better design can be discussed.
HTH