I am building an user input interface in R.
onload of the program, I would like like to ask the user what their preferences are according to a set of 6 fields. This will then be used as a comparison tool for the rest of the program.
e.g.,
>ThisProgram
>"Hello, on a scale of 1 to 10, how much would you say you rate the outdoors in your trips? Enter a 10 for very important, and a 1 for not important at all.
>7
>"Great. on a scale of 1 to 10, how much would you say you rate the Family Friendly in your trips? Enter a 10 for very important, and a 1 for not important at all.
>2
.
.
.
and so on...
how would I get R to ask the user a question, and then store the response in a vector?
See ?readline
> x <- readline("What is your name? ")
What is your name? Josh
> x
[1] "Josh"
Related
How to format the input file as expected output file?
Input file :
BROWSE-- userid.RESULT
COLUMNS 001 072 COMMAND INPUT ===>
SCROLL ===> PAGE
--------+---------+---------+---------+---------+---------+---------+---------+ SELECT LASTNAME, FIRSTNME, PHONENO 00010000
FROM DSN8C10.EMP 00020000
WHERE WORKDEPT = 'D11' 00030000
ORDER BY LASTNAME; 00040000
---------+---------+---------+---------+---------+---------+---------+---------+
LASTNAME FIRSTNME PHONENO
ADAMSON BRUCE 4510
BROWN DAVID 4501
JOHN REBA 0672
JONES WILLIAM 0942
LUTZ JENNIFER 0672
PIANKA ELIZABETH 3782
SCOUTTEN MARILYN 1682
---------+---------+---------+---------+---------+---------+---------+---------+
LASTNAME FIRSTNME PHONENO
STERN IRVING 6423
WALKER JAMES 2986
YAMAMOTO KIYOSHI 2890
YOSHIMURA MASATOSHI 2890
DSNE610I NUMBER OF ROWS DISPLAYED IS 11 DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 100
---------+---------+---------+---------+---------+---------+---- ---------+---------+---------+---------+---------+---------+----
DSNE617I COMMIT PERFORMED, SQLCODE IS 0 DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
---------+---------+---------+---------+---------+---------+----
DSNE601I SQL STATEMENTS ASSUMED TO BE BETWEEN COLUMNS 1 AND 72 DSNE620I NUMBER OF SQL STATEMENTS PROCESSED IS 1 DSNE621I NUMBER OF INPUT RECORDS READ IS 4 DSNE622I NUMBER OF OUTPUT RECORDS WRITTEN IS 30
Expected Output file :
ADAMSON BRUCE 4510
BROWN DAVID 4501
JOHN REBA 0672
JONES WILLIAM 0942
LUTZ JENNIFER 0672
PIANKA ELIZABETH 3782
SCOUTTEN MARILYN 1682
STERN IRVING 6423
WALKER JAMES 2986
YAMAMOTO KIYOSHI 2890
YOSHIMURA MASATOSHI 2890
There are a number of issues here. You appear to be running SPUFI interactively, you'd have to change that to a batch execution otherwise you'll be overwriting your userid.RESULTS dataset every time you use SPUFI for a different purpose. DSNTEP2 and DSNTEP4 are documented in the IBM DB2 documentation, be advised their output is limited to 133 bytes in width. This looks like it will work for your situation, but not necessarily in the general case.
After doing that, you have many options for reformatting your results, your shop's SORT utility, awk, sed, custom code you write yourself in Rexx, Java, PL/I, COBOL, C, C++, Python, and so forth. Choosing one of these is dependent on a number of factors including what products and languages are currently installed in your shop, your own skill set, size of the result set returned from DB2, which products and/or languages are currently being phased out of your shop, and so forth.
If you're going to go the custom code route, you might want to code your SELECT statement in that language (if it's supported) and do your data retrieval and reformatting all in one program.
Perhaps a better solution to your problem is to use Syncsort, if your shop has that product. Syncsort has the ability to execute a SELECT statement against DB2 and then process the result, reformatting as necessary. Bear in mind that while the ability is there, your shop may have elected not to use it.
As is often the case, you are well served by asking your peers and support staff how this type of challenge is normally met in your shop. Shop standards exist for many reasons, following them is in your best interest.
I am a total newbie to answer set programming, and I am struggling with a rather simple question. The program needs to be written in clingo.
So here is the question:
An abstract argumentation framework consists of a set A of arguments
and an attack relation R ⊆ A X A between them. For any two arguments
a1 and a2, if (a1, a2) ∈ R then we say that a1 attacks a2: if one
admits argument a1 then it casts doubts on argument a2. Formally, a
subset of arguments E ⊆ A is stable if the following two conditions
hold:
no arguments in E attack any other argument of E.
any argument outside of E is attacked by an argument from E.
Write an ASP program that identifies stable subsets of arguments in a
given instance through answer sets. The instance will be provided via
two predicates argument/1 and attack/2 corresponding to A and R
respectively.
Here is an example:
argument (a).
argument (b).
argument (c).
argument (d).
attack (a,b).
attack (b,c).
attack (d,c).
Valid output:
choose (a) choose (d)
This what I tried, which is obviously wrong:
choose(X) :- argument(X), attack(X,Y).
I don't know how to approach this at all.
Please help.
A simple 3 Step solving approach is the following:
describe the facts (check)
generate what you want as a result, but leave the program a choice
give rules which solutions do not apply
So start with 2:
generate possible outcomes. Think of it in simple words: For every argument I choose it or not.
The may or may not part can be solved with a subsum {}.
{choose(X)} :- argument(X).
or even simpler: I choose a subsum from the arguments
{choose(X):argument(X)}.
Lets check the solutions with Potassco and #show choose/1., resoning mode enumerate all:
Answer: 1
Answer: 2
choose(b)
Answer: 3
choose(c).
..
Answer: 15
choose(a) choose(b) choose(c)
Answer: 16
choose(a) choose(b) choose(c) choose(d)
SATISFIABLE
All combinations are found. Time to remove the wrong stuff. Again: think of it in simple words: It is not possible that I choose two arguments where one attacks the other. (If the head is left open, this is read a False.)
:- choose(X), attack(X,Y), choose(Y).
Now check it again:
Answer: 1
Answer: 2
choose(a)
Answer: 3
choose(d)
Answer: 4
choose(a) choose(d)
Answer: 5
choose(c)
Answer: 6
choose(a) choose(c)
Answer: 7
choose(b)
Answer: 8
choose(b) choose(d)
SATISFIABLE
Now we need to make sure every not choosen argument is attacked by a at least one choosen element:
1 {choose(Y):attack(Y,X)} :- argument(X), not choose(X).
Reads: For every argument X, which is not choosen, the number of choosen arguments which attack it, is at least one.
Lets check it:
Answer: 1
choose(a) choose(d)
SATISFIABLE
Nice.
Since the contraints are normally formulated with an empty head, lets reformulate the last rule:
:- argument(X), not choose(X), {choose(Y):attack(Y,X)} 0.
Reads: There is no argument X, which is not choosen and has maximum 0 choosen arguments, which attack X. It gives the same output.
Complete code:
argument (a;b;c;d).
attack (a,b).
attack (b,c).
attack (d,c).
{choose(X):argument(X)}.
:- choose(X), attack(X,Y), choose(Y).
:- argument(X), not choose(X), {choose(Y):attack(Y,X)} 0.
#show choose/1.
I am doing binary classification using vowpal-wabbit. A particular record(set of features) has 10 zeroes and 5 ones. So, I am creating two lines in vowpal-format
-1 10 `50 |f f1
1 5 `50 |f f1
Since the prediction(probability) for both these records would be same, I want to keep the same tag, so that I can dedupe the predictions({tag,prediction}) later and join with my original raw-data.
Is it possible to keep the same tag for more than one record in vowpal-wabbit?
First, the syntax above isn't correct
To be identified as such, tags should either:
Touch the | separator (no space between them) OR
The leading quote, needs to be a simple quote, not a backquote, by convention.
(or both).
Otherwise you get:
warning: `50 is not a good float, replacing with 0
warning: `50 is not a good float, replacing with 0
Which hints that vw interprets these "tags" as prediction-base.
For details, see Input format in the official documentation
Once the example is fixed to the correct syntax:
-1 10 '50|f f1
1 5 '50|f f1
Which runs fine, we can answer the question:
Is it possible to keep the same tag for more than one record in vowpal-wabbit?
Yes, you can. The tag is merely a simple way to connect input and output (when predictions are involved), there's no check for uniqueness anywhere. If you duplicate tags on input, you'll simply get the same duplicate tags on prediction output as well.
More notes:
Even if two examples are identical, you may get different predictions, if the model has changed somewhat in between them. Remember vw is an online learner, so the model can continuously change with each example unless you add the -t (test-only, don't learn) option.
Features whose value is zero are ignored, so you can drop them. The standard way in vw to say this is 'positive' and this is 'negative' is to use the values {+1, -1}. This is true for both labels and input features.
I want to edit some text like Female and Male because When I test them I found them as FemaIe and MaIe (I mean with Capital I not small L (l) ). And I want to solve this issue using ambfile like;
v1
6_tab_F_e_m_a_I_e_tab_6_tab_F_e_m_a_l_e_tab_1
4_tab_M_a_I_e_tab_4_tab_M_a_l_e_tab_1
But When I retest my results , they were worse. I found the Female as F and Male as M.
What I am doing wrong ? To use amb file like that is a wrong idea?
The fields should be tab separated, according to Tesseract Training Wiki.
[ set list N = 1 () set list N = 1
lput number-of-patches destination origin list N N + 1]
I wish to be able to store information about collections of patches and when the criteria for the filling of the list is met the number of the list will be increased. Will this code work?
Just looking at it, it will give you several syntax errors, regardless of whether the structure will do what you want. For example, the way you should construct a list with element '1' and name 'N' (which is what I think the first line is supposed to do) would be set N (list 1). You can test this by writing code as below and running test (eg by typing test in the command center at the bottom of the interface).
globals [N]
to test
set N (list 1)
print N
end
When writing code, your life is a lot easier if you build up the code in pieces, testing each one as you go either by inspecting agents to see if their property values change as you expect and/or putting print statements in lots of places to see what happens to your variables. This way you are introducing and fixing only a small number of errors in each step. Also, this means you are never writing code that you can't test immediately.