What is the correct interpretation for a number of OCL expressions that use "Shorthand for Collect"? - ocl

Given the following UML model:
I am struggling with the correct interpretation of some OCL expressions (all in context of class "City"). The version of OCL I'm working with is OCL 2.3.1 (though if OCL 2.4 is more suited for answering my question, for example because some aspects of OCL are more clear in OCL 2.4, I'm certainly interested).
If I want to ensure via OCL that each room in the city must have at least one window:
Let's forget about making "window" mandatory - the goal of this example is to understand how the OCL expression would need to look like.
inv: self.building.room.window->notEmpty() - As far as I understand OCL, this does not express the intent, since it means that the collection of all windows in the city must not be empty. The OCL expression uses what OCL 2.3.1 calls "Shorthand for Collect". The expression could also be written as inv: self.building->collect(room)->collect(window)->notEmpty(). Is this correct?
inv: self.building.room->forAll(r|r.window->notEmpty()) - This should express the intent - correct?
inv: self.building->forAll(b|b.room->forAll(r|r.window->notEmpty())) - This should also express the intent - correct?
Consider that another requirement would be that the area of each room must be greater than 0:
inv: self.building.room.area > 0 - Is this a valid expression? If it is:
How would this expression be evaluated (if the expression is valid) - with a check that each area value is greater than 0 (forAll), or just that one of the area values is greater than 0 (exists)?
In the OCL specification, I could not find anything that tells me if, in this expression, the collection of area values would all need to be greater than 0 (an implicit forAll()), or just one (an implicit exists()). Can you point me to the section(s) of the OCL specification that define the behaviour?
inv: self.building.room->forAll(r|r.area > 0) - This should express the intent - correct?

self.building.room.window => yes, yes, yes
You have successfully expanded collect in the first example. Do the same in the second, assuming room only has one area.
self->collect(building)->collect(room.area) > 0
which is badly typed: Bag(Integer) > Integer
self->collect(building)->collect(room.area)->size() > 0
is correctly typed but tests whether there is more than one area
self->collect(building)->collect(room.area)->sum() > 0
is correctly typed and detects whether any (assumed non-negative) area is non-zero
self->collect(building)->collect(room)->forAll(area > 0)
tests for non-singleton rooms
(If you use the Eclipse OCL Xtext Console you will see your type errors and intermediate types.)

Related

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.

Use the function "mod" in the instructions "if" and "select case"

I wrote a little code in Fortran. But the code doesn't behave as I thought, and I can figure out where is the problem.
I will not put the code here because it has 1200 lines but here its philosophy:
I create a 3D grid represented by a four dimensional table (I stock a vector of 2 elements on each point of the grid, corresponding at the nature of the site and who is occupying the site). This grid represents what we call a crystal (where atoms can be found periodically)
When this grid is constructed, the code scans each point of this grid and it looks to the neighboring sites to count the different type of atoms or the vacancies.
For this last point, I use a triple imbricated loop which permit to explore the different sites and I check the different neighboring site using either the if or the select case instructions. As I want my grid to be periodic, I have the function mod in the argument of the if or the select case.
The problem is sometimes, It found a different element in a neighboring site that the actual element in this specific neighboring site. As an example:
In the two ouput files where all the coordinates are written with the
element type I have grid(0,0,1)=-1 (which correspond to a empty site).
But while the code is looking to the neighboring sites of grdi(0,0,1) It tells that there is actually an element indexed 2 in grid(0,0,1).
I look carefully to the block in the triple implemented loop, but it seems fine.
I would like to know if anyone has already meet this kind of problem, or know if there is some problems using mod in a if or select case argument ?
If some of you want to look closer, I can send you the code, with some explanations.
Arrays are usually dimensioned as:
REAL(KIND=8),DIMENSION(0:N) ::A
or
REAL(KIND=8),DIMENSION(N) :: A
In the later example, they are assumed to start at 1.
You could also go (-N:N) or (10:191)
If you use the compiler switch '-check bounds' or ;-check all' you will see if you are going outside the array/etc. This is not an uncommon thing to get hosed up, but the compiler will abort quickly when the dimension is outside.
Once it works then removed the -check bounds and/or -check all.
Thanks for your consideration francescalus and haraldkl.
It was not related to the dimension of arrays Holmz, but thank you to try to help
It seems I finally succeed to fix it. I will post an over answer If I fully understand why it was not working properly.
Apparently, it was related to the combination of a different argument order in a call procedure and the subroutine header + a declaration in the subroutine with intent(inout).
It was like the intent(inout) was masking the problem. But It a bit strange for me.
Some explanations about the code :
As I said, the code create a 3D grid where each intersection of the 3D grid correspond to a crystallographic site. I attribute a value at each site -1 for an empty site, 1 for a crystal atom (0 if there is a vacancy instead of a crystal atom), 2,3,4,5 for different impurities. Actually, the empty sites and the sites which received crystal atoms are not of the same type, that's why an empty site and a vacancy are distinguished. The impurities can only occupied the empty site and are forbidden to occupied a crystal site.
The aim of the code is to explore the configurational space of the system, in other words all the possible distribution we can obtained with the different elements. To do so I start from a initial configuration and I choose randomly to site (respecting the rules of occupation) and I virtually switch them. I calculate the energy of the old an new configurations, if the new has a lower energy I keep it, if not, i keep the old one. The calculus of the energy is based on the knowledge of the environment of each vacancies and impurities, so we need to know their neighbors. And I repeat the all procedure again and again to converge to the most stable (so the most probable) configuration.
The next step is to include the temperature effect, and to add the second type of empty sites.
Have a nice day,
M.

How to set the alignment, or how to find PyGObject documentation

I am trying to right-align some text content in a CellRenderer. Through several searches I found two approaches, but these do not work. With bold-setting, you need to enable this feature first, so I am guessing I also need to enable alignment setting, but have not found how to do this. This runs without exception:
r = Gtk.CellRendererText()
r.props.width_chars = 10
r.set_property('alignment', Pango.Alignment.RIGHT) # no effect
r.props.alignment = Pango.Alignment.RIGHT # no effect
r.props.weight_set = True # not really needed
r.props.weight = Pango.Weight.BOLD # works, output is bold
This is what I guessed from the bold example but does NOT work:
r.props.alignment_set = True
The error is: 'gi._gobject.GProps' object has no attribute 'alignment_set'
Looking at these references I do not find something on GProps:
GObject Ref Manual
Gtk3 Ref Manual
This resource does say something about alignment, but it is unclear to me how to convert this C code to Python/GObject:
Gnome Gtk3 Manual for C
My question is how to fix this problem, where is the ref manual for this PyGObject error message, or how should I code the right-alignment?
Update:
I am currently looking at this similar SO question for clues.
As for the comment of TingPing, I looked at the set_alignment() method,and tried these:
r.set_alignment(Pango.Alignment.RIGHT) # error: set_alignment() takes exactly 3 arguments (2 given)
r.set_alignment(200, 0) # no error, no effect
besides this method seems intended to create some pixels padding at the left, which is not what I need: align text to the right of the cell space.
Update:
Perhaps the above code is good, but perhaps the CellRenderer() has no intrinsic width, no excess space to put to the left of the content. I thought of this because of thinking of simply left-padding my numberic cell content with spaces. Then I need to decide on the maximum field length. Perhaps the CellRenderer does not 'know' about a default field length. I added a settinge to .props.width_chars, but this did unfortunately not cause any rignt-alignment.
Through this C example I tried this to right-align:
r.props.xalign = 1.0
and it works! The xalign is the fraction of free space 0..1.0 to put to the left of the text. The value 0.5 will center the text.

Feature Extraction : SPTS and CAPP

I am trying to do facial expression recognition.I want to use Cohn Kanade dataset (The Extended Cohn-Kanade Dataset (CK+): A complete dataset for action unit and emotion-specified expression). In paper SPTS and CAPP are listed under section FEATURE EXTRACTION. But I can't find any other information on SPTS and CAPP.
What are Full forms of SPTS and CAPP?
From where I can start reading?
The paper is indeed not very good on providing the relevant information in an easily accessible way.
SPTS: "similarity normalized shape features"
CAPP: "Canonical normalized appearance"
CAPP: They cite 3: ( A. Ashraf, S. Lucey, J. Cohn, T. Chen, Z. Ambadar, K. Prkachin,
P. . Solomon, and B.-J. Theobald. The painful face: pain expression
recognition using active appearance models. In Proceedings of the
9th international conference on Multimodal interfaces, pages 9–14,
Nagoya, Aichi, Japan, 2007. ACM. 5)

SAP JCo 3 RFC RSAQ_REMOTE_QUERY_CALL - unexpected results

We’re using JCo 3.0 to connect to RFCs and read data from SAP R/3. We use one RFC RFC_READ_TABLE often and use a second custom RFC to read employee information. My questions revolve around a third RFC RSAQ_REMOTE_QUERY_CALL. I'm calling an ad-hoc query I built in SAP using this RFC but I’m not getting the expected results. The main problem is that it appears that SAP is ignoring one of my selection criteria and using what was saved in SAP when I originally built it. The date criterion stored in my ad-hoc is 6/23/2013. If I pass in 6/28/2013 from JCo, I get the same results as if I had passed 6/23/2013 from JCo.
We have built several ad-hoc queries whose only criteria is a personnel number and call them successfully using RFC RSAQ_REMOTE_QUERY_CALL.
Background on my ad-hoc query: reporting period of today, joining together four aspects of an employee’s information: their latest action (hire, rehire, etc.), organization (e.g. company), pay (e.g. pay scale level) and communication (e.g. email). The query will run every workday.
Here are my questions:
My ad-hoc has three selection criteria. The first two are simple strings. The third is a date. The date will vary each time the query runs. We are referencing the first criteria using SP$00001, the second with SP$00002 and the third with SP$00003. The order of the criteria changes from the ad-hoc to SQ01 (what was SP$00001 in the ad-hoc is now SP$00003). Shouldn’t we reference them in the order defined in the ad-hoc (e.g. SP$00001)?
The two simple string selections are using OPTION “EQ”. The date criteria is using OPTION GT (greater than). Is “GT” correct?
We have some limited accessibility to SAP. Is there a way to see which SP$ parameters are mapped to which criteria?
If my ad-hoc was saved with five criteria but four of them never change when I call the ad-hoc from JCo, do I just need to set the value of the one or do I need to set the other four as well?
Do I have to call this ad-hoc using a variant (function.getImportParameterList().setValue(“VARIANT”, “VARIANT_NAME”))?
Does the Reporting Period have an impact on the date criteria? I have tried changing the Reporting Period to be PNPBEGDA = today and PNPENDDA = today and noticed no change.
Is there a way in SAP to get a “declaration” of your ad-hoc (name, inputs, outputs, criteria)? I have looked at JCoFunction.toXml() and JCoFunctionTemplate. These are good if you want to see something at runtime before it goes to SAP, but I’m looking for something I can use on the JCo end to help me write Java code that matches the ad-hoc.
I have looked at length on the web for answers to my questions and have not found anything that is useful. If there is anything which would help me, please let me know.
Thanks,
LM
Since I don't know much about SQnn, I won't be able to answer all of your questions...
I don't know, sorry.
It should be, at least it's the usual operator for greater than.
Yes - set an external breakpoint right inside the function module and trace its execution while performing the RFC call. Warning: At least basic ABAP knowledge required.
I don't know, sorry.
I don't know either, sorry.
That would depend on the query, I suspect...
JCo won't be able to help you out there - it doesn't know about queries, it only knows function modules. There might be other RSAQ_* function modules to get that information though.
I played with setting up a variant in SQ01 for my query. I added some settings in the variant that solved my problem and answered several of my questions in my post. The main thing I did was add a dynamically calculated date as part of my criteria. Here's how:
1. In SQ01, access menu "Go To" -> "Maintain Variants".
2. Choose your variant and in subobjects, choose "Attributes" and click "Change".
3. In the displayed list, find your date criterion.
4. Choose "D" in Selection Variable, choose a comparison option (mine was GT for greater than), and a "Name of a Variable" (really, this is the type of dynamic date calculation you need).
5. Go back to the Subobjects panel, choose "Values" and click "Change".
6. Enter any other criteria you need in the "Program selections" section.
7. Save the variant.
By doing this, I don't need to pass anything into the query from JCo. Also, SAP will automatically update the date criteria you entered in step #4 above.
So to to answer my questions from my original post:
1 and 4. It doesn't matter because I'm no longer passing anything in from JCo.
2. "GT" is Greater Than.
3 and 7. If anyone knows, I'd really like to find out.
5. Use the name you as it is in SAP (step #2 above).
6. I still don't know, but it's not holding me up.
I'm posting this in case anyone out there needs this type of information. Thanks to Esti and vwegert for helping me out.