Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
defmacro
Sep 27, 2005
cacio e ping pong

Presa Canario posted:

I'm trying to write an AI game search tree with a depth-first search in java. I already have a recursive version that works, but this seems like it would be a lot faster. The problem is it needs to iterate somehow so that I can stop it at a maximum depth, and so that I can do min/max at certain levels. I tried doing this:

code

...but depth never goes back up once it hits the bottom two levels. It there a better way or should I stick with recursive?

You seem to be increasing the 'depth' value based on the number of children the node at depth = 0 has, which I don't think is what you want to do. The difference between the depth of the current value, and the next value on the top of the stack is what is going to change the depth. It would probably be better to store the depth of nodes, along with the nodes themselves, so you don't have to handle any incrementing. If you had a tree like this:



And your last node by depth would be node 7, your code will only increment the depth by 1, rather than returning to depth 1 (where nodes 2/3 are).

defmacro fucked around with this message at 18:41 on Mar 28, 2008

Adbot
ADBOT LOVES YOU

defmacro
Sep 27, 2005
cacio e ping pong

happylf posted:

How different are Scheme and Common LISP? Similar like C++ and Java?

The two big differences are namespaces and libraries. You'll see Scheme and Common Lisp referred to as Lisp-1 and Lisp-2 respectively. Lisp-1's have everything in one namespace (functions, variables, etc.) while a Lisp-2 has separate namespaces for the previously mentioned things. Because of this, Common Lisp code can get a little messy when you're dealing with function application. This paper explains the differences much more extensively.

Scheme is generally used as a teaching language because the language itself is very small. Common Lisp has a much more robust built-in library (this might be a good comparison between Java and C++ without the STL). I'd argue if you wanted to develop a 'serious' application, you'd want to use Common Lisp, but if you just want some experience with functional programming, Scheme would be a better choice.

There are some other minor differences between the two (syntax, Scheme can generally compile to C or binaries more easily than Common Lisp, etc.), but these are the biggest.

defmacro
Sep 27, 2005
cacio e ping pong

Neslepaks posted:

I have no idea what this means, but I don't think the comparison is similar on anything but a very superficial level (small/non-oo vs big/oo).

That's probably the only level that would really matter to a beginner.

defmacro
Sep 27, 2005
cacio e ping pong

Neslepaks posted:

But the discussion was whether or not learning Scheme and CL at the same time would be confusing. And I stand by my claim that it wouldn't, at least not in any degree approaching what it would be to learn C and C++ at the same time. :)

Well, agreed in that case.

defmacro
Sep 27, 2005
cacio e ping pong

Plastic Jesus posted:

alias wireshark='open -a /Applications/Wireshark.app'

There is no reason to use xterm/iterm/anydamnedterm on OS X.

Except for, you know, using terminal applications.

defmacro
Sep 27, 2005
cacio e ping pong
VVV good point, moved my questions to the RoR thread.

defmacro fucked around with this message at 01:03 on Jul 25, 2008

defmacro
Sep 27, 2005
cacio e ping pong

rjmccall posted:

code:
if
is a special form in LISP/Scheme that can't be duplicated by a simple user-defined function, precisely because it only evaluates one of its second and third arguments, and which one depends on the result of the first. I believe it can be duplicated with a macro, though.

For example:

code:
CL-USER> (defmacro newif (condition form1 form2)                                                                                             
           `(cond (,condition ,form1)                                                                                                        
                  (t ,form2)))
NEWIF                                                                                                                                        
CL-USER> (newif (= 0 0) 3 4)
3                                                                                                                                            
CL-USER> (newif (= 0 0) 3 (print "rear end"))
3
But we your definition
code:
CL-USER> (defun my-if (x y z)                                                                                                                
           (if x                                                                                                                             
               y                                                                                                                             
               z))
MY-IF                                                                                                                                        
CL-USER> (my-if (= 0 0) 3 4)
3                                                                                                                                            
CL-USER> (my-if (= 0 0) 3 (print "rear end"))
                                                                                                                                             
"rear end"                                                                                                                                        
3
As you can see, it still returns the correct answer, but it evaluates both forms which it shouldn't. Essentially, the Lisp macro returns the form wrapped in (COND) without evaluating each form first. It only evaluates forms it needs to, making it more "correct".

defmacro
Sep 27, 2005
cacio e ping pong

Vanadium posted:

Can you implement cond with a macro, without using if or whatever? :colbert:

Here's IF without COND
code:
CL-USER> (defmacro coolif (condition then-branch else-branch)
           `(or (and ,condition ,then-branch)
                ,else-branch))
COOLIF
CL-USER> (coolif (= 0 0) 3 4)
3
CL-USER> (coolif (= 0 0) 4 3)
4
CL-USER> (coolif (= 0 0) 4 (print "rear end"))
4
I removed the note that was printed after the last call. It was removing the unexecutable code after the short circuiting.

There's IF. COND is based (generally) an IF, you could see some sample source here. Here's it defined with my IF:
code:
CL-USER> (defmacro coolcond (&rest clauses)
           (coolif (endp clauses)
                   nil
                   (let ((clause (first clauses)))
                     (when (atom clause)
                       (error "coolcond clause is not a list: ~S" clause))
                     (let ((test (first clause))
                           (forms (rest clause)))
                       (coolif (endp forms)
                               (let ((n-result (gensym)))
                                 `(let ((,n-result ,test))
                                    (coolif ,n-result
                                            ,n-result
                                            (coolcond ,@(rest clauses)))))
                               `(coolif ,test
                                        (progn ,@forms)
                                        (coolcond ,@(rest clauses))))))))
COOLCOND
CL-USER> (macroexpand-1 '(coolcond ((= 0 0) 3) ((= 0 1) 4) (t 2)))
(COOLIF (= 0 0) (PROGN 3) (COOLCOND ((= 0 1) 4) (T 2)))
T
CL-USER> (coolcond ((= 0 0) 3) ((= 0 1) 4) (t 2))
3
CL-USER> (coolcond ((= 0 1) 3) ((= 0 1) 4) (t 2))
2
CL-USER> (coolcond ((= 0 1) 3) ((= 1 1) 4) (t 2))
4
Generally IF is written as a special form and COND is written as a macro using IF, as seen in the above code. You could write COND with just AND/OR/etc. but it'd probably be a pain in the rear end. Obviously, the copy/pasted macro is nicer than mine (gensyms to prevent symbol collisions etc.) but I think you get the idea.

ps: lisp rules :colbert: :coal:

defmacro fucked around with this message at 23:00 on Sep 16, 2008

defmacro
Sep 27, 2005
cacio e ping pong

Vanadium posted:

Now if only someone would take all the cool features and put them into a useful language. :c00lbert:

that's cool, not enough parentheses though

defmacro fucked around with this message at 18:37 on Sep 16, 2008

defmacro
Sep 27, 2005
cacio e ping pong

Clock Explosion posted:

So, does anyone know of any resources about programming a shell, as in writing a CLI, as opposed to shell programming?

I have an idea for a research project for my Systems class, but I need some sort of resource on my proposal.

So far, I've found the source code of the BSH, and that's it, as well as maybe one article in the ACM's Digital Library which I don't have access to.

You might want to check out the CS:APP shell lab for this. It's what we used in my systems class and was a pretty fun lab.

defmacro
Sep 27, 2005
cacio e ping pong

Triple Tech posted:

Modern RDBMSes are based on arrays, right? So the data is stacked together, side by side as columns, and then rows, and it makes access really fast...

But what if we had a database that was more suited for like... Trees? Like HTML or XML documents. How does that get represented as a stream of bytes in memory or on a disk? I'm thinking a linked list of some sort could solve the problem in some abstract way, but then the data isn't side by side anymore and makes lookups really slow. How are databases like this implemented?

The closest thing to what you're asking that I'm aware of is indexing XML documents into relational databases, mainly done for scaling up the search of XML documents. Naturally, this is much faster and uses less memory than building up a tree and searching that. It isn't a terribly elegant approach, but considering the years of work done in databases, leveraging a seasoned field to improve search is a pretty killer idea.

defmacro
Sep 27, 2005
cacio e ping pong

rugbert posted:

does anyone remember that desktop interface we all made a few years back? It was called tsDesk or something? It was originally made by 69apples or someone..

I was asked to help with a project recently and if I can find out old work it would really help.

this?

googling "tsdesk" seemed to help

defmacro
Sep 27, 2005
cacio e ping pong

Plorkyeran posted:

What exactly do you gain from validation that says that asdjfhklsdjfh@sdjhfiuyiulkjdhf.com is a valid email address?

The truth is more important than the email account itself.

Duh.

defmacro
Sep 27, 2005
cacio e ping pong

NO! I DONT DO ANAL! posted:

Hmm, could be stack overflow... Here, have a gigantically trimmed-down version of the output for (! 1362)

code:
crazy loving error message
The ^ function has the same cutoff ( (^ 2 1361) works, (^ 2 1362) doesn't) so you're probably right and the cutoff is on stack capacity. Thanks guys!

Is there any reason you're using ACL2 in lieu of a nicer Lisp implementation (mzscheme, SBCL, Clojure, CLisp, etc.) for general programming? ACL2 is for computer-aided proofs, not general purpose programming. Here's the error generated by SBCL:
code:
* (defun ! (x) (if (zerop x) 1 (* x (! (- x 1)))))
* (! 1000000)
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread #<THREAD "initial thread" RUNNING {1192B6C9}>:
  Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.
or Clojure
code:
user=> (defn ! [x] (if (zero? x) 1 (* x (! (dec x)))))
#'user/!
user=> (! 100000000)
java.lang.StackOverflowError (NO_SOURCE_FILE:0)
Both of which are very clear and more suited to factorial and above programming.

defmacro fucked around with this message at 03:40 on Mar 25, 2010

defmacro
Sep 27, 2005
cacio e ping pong

Scaramouche posted:

Has anyone done any work around pluralization and synonyms as it relates to search keywords? I'm wondering if there are any readily available synonym dictionaries or thesauri out there that can be used for matching, that would handle plurals properly such Dress versus Dresses or Pants versus Pantses. We can make up some rules as well (such as if *s,*ses then -s and so on) but it obviously won't catch all cases. Maybe even a list of exceptions if anyone's come across one.

Here are some resources:

nifty web-based pluralizer
paper on the issue
rules for irregular plurals

defmacro
Sep 27, 2005
cacio e ping pong

Scaramouche posted:

Thanks for the references. I've passed them on to the programmer working on it, hopefully they'll help him. I was more looking for shortcuts since sometimes these guys see the 'hard' solution as elegant and I'm more of a 'get-r-done' kind of guy.

There are pre-fab'd stemmers (like Porter) that have rules to turn plural words into word stems. You may be able to use one of these to check against the special cases to ensure your code is working properly. Aside from googling around for code fragments, this your best "get-r-done" bet. It's certainly gross though and in all honesty, probably won't work too well.

defmacro
Sep 27, 2005
cacio e ping pong

nielsm posted:

In bash, you can add 2>&1 in before the |tee part, to redirect standard error to standard out.

Most shells support &| as a shortcut for 2>&1 |.

defmacro
Sep 27, 2005
cacio e ping pong

TasteMyHouse posted:

homebrew owns. It's the kind of thing that makes me want to learn Ruby better... but I feel like I'm betraying Python

The amount of Ruby you need to understand to write a formula is tiny. Just read a few formulas and you should be good to go.

defmacro
Sep 27, 2005
cacio e ping pong

Shaocaholica posted:

Does anyone know how I can something similar to this but instead of a single sequential process, spawn multiple processes/threads?

code:
#! /usr/local/bin/tcsh -fb

foreach some_file ( `find . -type f -name \*.poo` )
    echo $some_file
    convert $some_file $some_file:r.pee
end
Doesn't have to be tcsh.

If you'd rather stick to the shell, give parallel a try.

defmacro fucked around with this message at 22:23 on Oct 25, 2011

defmacro
Sep 27, 2005
cacio e ping pong

AlsoD posted:

I'm just starting to use LaTeX and while finding out how to do a particular thing doesn't seem that hard, knowing what to do is a lot less certain.

I'm essentially writing a report containing code snippets (Haskell if it matters). Would the best way to have verbatim (or alltt) blocks around the code, make it a monospaced font and then format it myself, or use a library like listings to format it for me?

I'm pretty close to just giving up and slapping it into OpenOffice but I wanted to try and learn something new. Any tips?

listings sucks, I'd recommend you use minted/pygments if you can get it to work. The results are head and shoulders above what listings can do. This will require some more upfront time getting used to the library, but it's well worth it.

Also, make sure you're using an editor with some kind of snippet functionality (vim/emacs/TextMate/whatever). This allows you to type sec<TAB> and it autofills the markup for a section declaration and let's you tab through the fields. An absolute must if you become a heavy LaTeXer. And if you get stuck, you'll probably get better answers in the LaTeX Megathread.

edit: This is a good general LaTeX guide. I'd read at least the first two sections, add in the third if you'll be doing lots of math. I still pull this up every so often as a reference.
edit2: VVV that rules

defmacro fucked around with this message at 05:04 on Oct 26, 2011

defmacro
Sep 27, 2005
cacio e ping pong

GregNorc posted:

R stuff

Some general R tips:
  • When you need help with a function (i.e., write.csv) enter ?write.csv or help(write.csv) in R and it'll give you a manpage-like description of the function.
  • The CRAN manuals are good, also check out Quick-R. This helped me get up to speed.
  • A GUI like RStudio may be helpful.

defmacro
Sep 27, 2005
cacio e ping pong

GregNorc posted:

So I''m trying to use subset() in R to remove inelligible participants from some study data.

subset(lShare, yob >= 1994 & shares_yn=="Yes" & time_in_country >= 5)

Which returns nothing. I think the issue is I need to specify a SELECT statement, but I'm unsure how to specify I want to return all columns (I tried * and ALL to no avail...)

subset() returns all columns by default, you don't need to specify it with select:
code:
> subset(airquality, Ozone > 40 & Day == 1, select=colnames(airquality))
    Ozone Solar.R Wind Temp Month Day
1      41     190  7.4   67     5   1
62    135     269  4.1   84     7   1
124    96     167  6.9   91     9   1
> subset(airquality, Ozone > 40 & Day == 1)
    Ozone Solar.R Wind Temp Month Day
1      41     190  7.4   67     5   1
62    135     269  4.1   84     7   1
124    96     167  6.9   91     9   1
Are you sure your subset formula is correct and your data.frame contains rows that satisfy your formula?

EDIT: Not sure how I missed the earlier post.

defmacro fucked around with this message at 20:27 on Dec 1, 2011

defmacro
Sep 27, 2005
cacio e ping pong

Gin_Rummy posted:

Highly probable, though I can't say for sure. The training set was massive... thousands and thousands of emails.

That looks like the issue to me. You're making a separate CountVectorizer for the second dataset, so it's vectorizing things differently. Use
code:
message_bow.transform(df_2...
instead.

defmacro
Sep 27, 2005
cacio e ping pong

Gin_Rummy posted:

Is "transform" the proper library call? Different variations of message_bow.transform, fit, and fit_transform have given me a new type of value error. If I am no longer using "CountVectorizer" would I still be able to call my analyzer, which was meant to parse my input text?

<snip>

Ah sorry, I remembered the syntax incorrectly. You'll want to do something like this:

code:
vectorizer = CountVectorizer(analyzer = process_text)
message_bow = vectorizer.fit_transform(df['text'].fillna(' '))
...
df2 = vectorizer.fit(df_2['Message'].fillna(' '))
...
The vectorizer object will still have the appropriate analyzer for subsequent calls.

The three methods of a vectorizer do the following things:
* fit fits the words to the vectorizer and updates it's internal state
* transform, given an existing fitted vectorizer, returns the transformed vectors
* fit_transform does both

A contrived example:

code:
>>> import sklearn
>>> from sklearn.feature_extraction.text import CountVectorizer
>>> vectorizer = CountVectorizer()
>>> df = vectorizer.fit_transform("wu tang clan ain't nothing to gently caress with".split())
>>> df.todense()
matrix([[0, 0, 0, 0, 0, 0, 0, 1],
        [0, 0, 0, 0, 1, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 1, 0, 0],
        [0, 0, 1, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 1, 0]])
>>> df2 = vectorizer.transform("well here are some words you can gently caress with".split())
>>> df2.todense()
matrix([[0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 1, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 1, 0]])
>>> df.shape
(8, 8)
>>> df2.shape
(9, 8)
Note the last two rows in both dataframes are the same, because it was the same word. Also note the all zero vectors in df2, showing the vectorizer doesn't know the words. Importantly, the shapes are right. Each dataframe has 8 column features corresponding to the 8 words known by the vectorizer when it was fit. It's important that the inputs to the vectorizer are the same shape like in the example above both are a list of individual words. Or in your example, likely a list of messages you want to classify as spam vs. ham.

defmacro fucked around with this message at 14:42 on Nov 4, 2021

Adbot
ADBOT LOVES YOU

defmacro
Sep 27, 2005
cacio e ping pong

Gin_Rummy posted:

Just reporting back to thank you all for the ML guidance. I was able to sort through most of the problems and get it working! Now I have to ask if anyone can recommend a good way to "call" my trained model in another script/instance?

I am thinking if I pickle my classifier and the vectorizer (and probably the bag of words too?), I can call each of the files in another script... however I don't seem to be able to pickle the analyzer (my process_text function) with my vectorizer, which makes it DOA in any new script.

An error would help! I googled and found this saying you might just need to import it, but it's from a decade ago so who knows.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply