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
raminasi
Jan 25, 2005

a last drink with no ice

Rocko Bonaparte posted:

Yeah, my question needs some work. I'll elaborate tonight. I think it's something like facades and adapters, but I omitted some information.

You know that you don't need an Official GoF-Approved Word to build the thing you need, right?

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

GrumpyDoctor posted:

You know that you don't need an Official GoF-Approved Word to build the thing you need, right?

I have a Captain Actually McPedantic I was dealing with. I mentioned creating a bridge and then it started.

Peristalsis
Apr 5, 2004
Move along.
I hope this is a simple, stupid question, but I'm pretty inexperienced with JavaScript and JQuery, and I'm not having much luck getting exactly what I need with Google. Hopefully, it'll be a nice, easy softball for someone to start off their day with.

I have a JQuery $(document).ready method that sets a callback for a widget to an anonymous function defined in the callback argument. So far, so good. Now, I need a named function that I can call from a couple of places - once in the $(document).ready method, and then I also need to invoke it from that anonymous callback method. This function will probably involve an AJAX call to get data to populate a pulldown list. My problem is that every example I see uses anonymous functions. How and where do I make an actual, named function? Does the function def go inside of the $(document).ready method or outside of it? Can this function be a JQuery construct, or does it have to be a pure JS method? And if it has to be JavaScript, do I need to put it in a JS-specific HTML tag, or can it live in the same <script> element as the $(document).ready definition?

Here's what I basically have:
code:
<script>
  $(document).ready(function() {
    populate_my_other_widget_with_ajax_call ()                                      <-- Call this when page loads
    $('#my_widget').change(function() {
      $('input#my_hidden_input_var').val($(this).val());
      populate_my_other_widget_with_ajax_call()                                     <-- Call it again whenever my_widget changes
    }
  }
</script>
Basically, the question is how and where to I create populate_my_other_widget_with_ajax_call?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Peristalsis posted:

Basically, the question is how and where to I create populate_my_other_widget_with_ajax_call?

JavaScript code:
<script>
  $(document).ready(function() {

    //right here works just fine and is actually preferable to anywhere else given your example code

    populate_my_other_widget_with_ajax_call ()                                      <-- Call this when page loads
    $('#my_widget').change(function() {
      $('input#my_hidden_input_var').val($(this).val());
      populate_my_other_widget_with_ajax_call()                                     <-- Call it again whenever my_widget changes
    }
  }
</script>
You seem to have some strange ideas about how JavaScript and jQuery actually work so let me try to address what I noticed.

You can define a function just about anywhere. If it's inside another function, functions defined outside that function won't be able to see it because it's basically the same thing as

JavaScript code:
function get_stuff_done() {
  var do_stuff = function() {
    //stuff!
  };
  do_stuff();
}
and do_stuff isn't visible outside of get_stuff_done because it's declared as a var which is actually a good thing! You're not polluting the global scope that way. http://dailyjs.com/2012/07/23/js101-scope/

jQuery 'constructs' are JS objects with properties that are functions.

When the browser evaluates the scripts on a page, it logically just concatenates them all and runs the code in that order (unless there's an async or defer attribute on a non-inline script, but that's a special case and not widely used AFAIK https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) so nothing really needs to be in its own element.

hooah
Feb 6, 2006
WTF?
Paging Nippashish.

I've built my Viterbi decoder (I think - it runs, at least), but it's tagging everything "OTHER". Do you know of any common mistakes I should check out?

FistLips
Dec 14, 2004

Must I dream and always see your face?
I'm new to Excel and programming in general and I'm trying to make a macro for updating a sheet based on an update in another sheet. If anyone would be willing to help me with this I would appreciate this greatly!

Peristalsis
Apr 5, 2004
Move along.

Munkeymon posted:

JavaScript code:
<script>
  $(document).ready(function() {

    //right here works just fine and is actually preferable to anywhere else given your example code

    populate_my_other_widget_with_ajax_call ()                                      <-- Call this when page loads
    $('#my_widget').change(function() {
      $('input#my_hidden_input_var').val($(this).val());
      populate_my_other_widget_with_ajax_call()                                     <-- Call it again whenever my_widget changes
    }
  }
</script>
You seem to have some strange ideas about how JavaScript and jQuery actually work so let me try to address what I noticed.

You can define a function just about anywhere. If it's inside another function, functions defined outside that function won't be able to see it because it's basically the same thing as

JavaScript code:
function get_stuff_done() {
  var do_stuff = function() {
    //stuff!
  };
  do_stuff();
}
and do_stuff isn't visible outside of get_stuff_done because it's declared as a var which is actually a good thing! You're not polluting the global scope that way. http://dailyjs.com/2012/07/23/js101-scope/

jQuery 'constructs' are JS objects with properties that are functions.

When the browser evaluates the scripts on a page, it logically just concatenates them all and runs the code in that order (unless there's an async or defer attribute on a non-inline script, but that's a special case and not widely used AFAIK https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) so nothing really needs to be in its own element.

I'm a bit late with this, but thanks for the info. You're right that I don't know much about JavaScript and JQuery. I've mostly avoided them thus far in my career, but I have to do some Ajax stuff for my current project, and I'm trying to muddle through them as best I can, until I can make some time to learn them better. The code organization for them always just seems off somehow, so I'm never sure if I'm missing something, or if I'm just looking at bad examples.

Jose Cuervo
Aug 25, 2004
This question concerns implementing Common Random Numbers in a simulation model (coded in Python, but I think the question is language agnostic).

The simulation is a small supply chain which has 4 factories producing goods and where I would like to be able to compare inventory policies. The amount of raw material used each day at each factory is a random variable (so 4 numbers drawn from the random number stream). The inventory policy at each factory determines when new raw material will be ordered so that the factory does not run out of raw materials, and the time it takes the raw material to arrive at the factory is a random variable (a single number drawn from the random number stream).

In order to implement common random numbers I need to make sure that the amount of raw material used at each factory each day is the same regardless of the policy being used, however I cannot think of a way to ensure this happens using a single random number stream: under different policies the random number used as the time it takes a reorder to arrive at the factory can be a different random number in the random number stream. For example, if under policy_1 raw material is not reordered until day 6 at Factory 1, but under policy_2 it is reordered on day 4, and assuming that no other factories reorder, then under policy_1 the random number used as the time it takes a reorder to arrive is the twenty-fifth number in the random number stream, but under policy_2 it is the 17th.

Thus it appears I need five random number streams (one for the amount of raw material used, and one each for the amount of time it takes a reorder to arrive at the factory). Am I missing something?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Peristalsis posted:

I'm a bit late with this, but thanks for the info. You're right that I don't know much about JavaScript and JQuery. I've mostly avoided them thus far in my career, but I have to do some Ajax stuff for my current project, and I'm trying to muddle through them as best I can, until I can make some time to learn them better. The code organization for them always just seems off somehow, so I'm never sure if I'm missing something, or if I'm just looking at bad examples.

It's a screwy language dressed up to look like the ones you're probably used to so, yeah, if you're expecting it to act like Java or C# you're going to be very confused. Also there's an excellent chance the examples are terrible, too - that's why I linked the article explaining scope. I can dig up some other beginner stuff from when we brought on a junior dev the other year if you want.

I should probably do a big write-up on coming to JS from the C#/Java world because that's a transition I made the hard way. Actually, doing it on IE 6 means I probably did it the really hard way :suicide:

Nippashish
Nov 2, 2005

Let me see you dance!

hooah posted:

I've built my Viterbi decoder (I think - it runs, at least), but it's tagging everything "OTHER". Do you know of any common mistakes I should check out?

Run through a small example by hand and make sure your decoder gets the same answer.

hooah
Feb 6, 2006
WTF?

Nippashish posted:

Run through a small example by hand and make sure your decoder gets the same answer.

Ok, I think part of the problem is that I'm not dealing with log probabilities properly. For the small example, I decided to just use as a training sentence "<ENAMEX TYPE="PERSON">Pierre Vinken</ENAMEX> , <TIMEX TYPE="DATE:AGE">61 years old</TIMEX> , will join the <ENAMEX TYPE="ORG_DESC:OTHER">board</ENAMEX> as a nonexecutive <ENAMEX TYPE="PER_DESC">director</ENAMEX> <TIMEX TYPE="DATE:DATE">Nov. 29</TIMEX> . ". Then for testing, I just used "Pierre Vinken , 61 years old .". My problem with the probabilities is how to treat things that don't happen. For instance, in the first step, PERSON is the only tag that should have any meaningful value for tag_sequence_log_prob (log2(1/1) = 0). However, since the other tags don't happen after start in the training, they're also coming out to 0, but for a different reason. I know about smoothing in theory, and I think that's what I need to do, but I don't really understand how to apply it.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jose Cuervo posted:

Thus it appears I need five random number streams (one for the amount of raw material used, and one each for the amount of time it takes a reorder to arrive at the factory). Am I missing something?

Using a unique random number stream for each factory's time-to-arrive doesn't seem anything like using common random numbers. Surely you just need two streams, one for each purpose the random numbers get used for?

Jose Cuervo
Aug 25, 2004

Jabor posted:

Using a unique random number stream for each factory's time-to-arrive doesn't seem anything like using common random numbers. Surely you just need two streams, one for each purpose the random numbers get used for?

What I am concerned with achieving is (from the Wikipedia link):
code:
... a specific random number used for a specific purpose in one configuration is used for exactly 
the same purpose in all other configurations. For example, in queueing theory, if we are comparing 
two different configurations of tellers in a bank, we would want the (random) time of arrival of the
Nth customer to be generated using the same draw from a random number stream for both configurations.
Suppose that under policy_1 the order of draws is: [1 2 1 3 2 3 2 3 1 4 2 4 3 2] while under policy_2 the order of draws is [1 2 1 4 3 3 2 3 1 4 2 4 3 2], where i={1, 2, 3, 4} represents the factory that the draw belongs to. If I used a single random number stream for all factories time-to-arrive, then under different policies the same draw is not necessarily used for both policies (for instance the first time-to-arrive for factory 4 is the 10th draw in the random number stream under policy_1 but is the 4th draw in the same random number stream under policy_2).

The only way I can think of to guarantee that the same time-to-arrive is used in both (or really in all) policies is to have a unique random number stream for each factory's time-to-arrive.

Nippashish
Nov 2, 2005

Let me see you dance!

hooah posted:

I know about smoothing in theory, and I think that's what I need to do, but I don't really understand how to apply it.

The simplest form of smoothing is just to add 1 to all of your counts. If you saw the sequence <START> <PERSON> 10 times then just pretend you saw it 11 times, and that means if you saw the sequence <START> <END> 0 times then you pretend you saw it 1 time and now you don't need to try to work with log(0).

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jose Cuervo posted:

What I am concerned with achieving is (from the Wikipedia link):
code:
... a specific random number used for a specific purpose in one configuration is used for exactly 
the same purpose in all other configurations. For example, in queueing theory, if we are comparing 
two different configurations of tellers in a bank, we would want the (random) time of arrival of the
Nth customer to be generated using the same draw from a random number stream for both configurations.
Suppose that under policy_1 the order of draws is: [1 2 1 3 2 3 2 3 1 4 2 4 3 2] while under policy_2 the order of draws is [1 2 1 4 3 3 2 3 1 4 2 4 3 2], where i={1, 2, 3, 4} represents the factory that the draw belongs to. If I used a single random number stream for all factories time-to-arrive, then under different policies the same draw is not necessarily used for both policies (for instance the first time-to-arrive for factory 4 is the 10th draw in the random number stream under policy_1 but is the 4th draw in the same random number stream under policy_2).

The only way I can think of to guarantee that the same time-to-arrive is used in both (or really in all) policies is to have a unique random number stream for each factory's time-to-arrive.

Ah, sure.

What's your objection to having a different random number stream for each of these purposes?

Jose Cuervo
Aug 25, 2004

Jabor posted:

Ah, sure.

What's your objection to having a different random number stream for each of these purposes?

Absolutely no objection. My next question is how to successfully implement this.

I need s = 5 unique random number streams for each simulation replication r. I also need to use the same s = 5 unique random number streams for the r-th simulation replication of the p-th policy.

In Python I could initialize a single random number stream using r (the index of the simulation replication). Then the first of the s unique random number streams would be initialized using the first s draws from that random number stream:
Python code:
import import numpy.random as npr

def int_seed(random_stream):
    """Use random_stream to compute an integer seed that is bounded
    above.
    @rtype : int
    """
    return random_stream.randint(10000000)


r = 101
rep_rand_strm = npr.RandomState().seed(r)

raw_mat_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac1_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac2_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac3_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac4_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
In this way no matter what the policy is, I know that if r=101 I will have the same 5 unique random number streams, right?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I think I'm looking for something like a distributed publish/subscribe framework that works well in Python, but could also cooperate with C, C#, and Java. I mean, I might be wrong.

We have a bunch of experiments here that different groups need to use for different purposes. So some of them have to do extra things at key points in the experiments--usually to facilitate equipment. One way to do this is something like the Strategy pattern, where we just break the experiments up by their phases. However, I did not necessarily want to refactor all the experiments to fit that paradigm, and we might hit some strain in how the strategy is defined. So I was thinking of just having some events that are put in around the key points. Some of these event callbacks would have to be blocking; they'd have to wait for the listeners to complete their reaction to the event before moving forward. Is that a common enough thing in publish-subscribe frameworks?

The distributed requirement is not for running across multiple computers, but just for running across multiple processes. I'm trying to get various agents to work with each other without having to couple them up.

I'm currently trying to see if Redis will do this. So I would be curious if there is something better, or if I'm on drugs and should reconsider the whole notion.

nielsm
Jun 1, 2009



Redis will probably do what you want, in one form or another.

Also look at ZeroMQ, it's not quite the same but it gives you some abstracted IPC in a socket-like way, I believe it has both unicast and multicast.

hooah
Feb 6, 2006
WTF?

Nippashish posted:

The simplest form of smoothing is just to add 1 to all of your counts. If you saw the sequence <START> <PERSON> 10 times then just pretend you saw it 11 times, and that means if you saw the sequence <START> <END> 0 times then you pretend you saw it 1 time and now you don't need to try to work with log(0).

I'd totally forgotten about add-one smoothing, which was pretty easy to implement. However, now the problem is how to make the algorithm recognize multi-word entities. This appears to be what the "chunk" part of the HMM chunk tagger they're referring to means, but I don't understand how they did it.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Rocko Bonaparte posted:

Some of these event callbacks would have to be blocking; they'd have to wait for the listeners to complete their reaction to the event before moving forward. Is that a common enough thing in publish-subscribe frameworks?

You mean RPC? Yeah, I'd say so: https://www.rabbitmq.com/tutorials/tutorial-six-python.html

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo Ă°ÂŸÂ’Â‹ Ă°ÂŸÂ™Â
Taco Defender

Akumu posted:

I just got a mysterious e-mail that only included a Base64 encoding of a 24-digit decimal number. Is that a format that any particular thing comes in?

I got an identical email, but the decimal number was longer. I looked for patterns briefly and then decided it was just a broken spam bot.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

2015-04-23T20:31:12.486Z

What standard is a datetime of that format?

nielsm
Jun 1, 2009



Thermopyle posted:

2015-04-23T20:31:12.486Z

What standard is a datetime of that format?

ISO 8601

EAT THE EGGS RICOLA
May 29, 2008

Thermopyle posted:

2015-04-23T20:31:12.486Z

What standard is a datetime of that format?

ISO 8601

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

thx

fritz
Jul 26, 2003

What's a good resource for learning about windows system programming? I've been doing unix basically my whole career, and things are feeling very strange.


ETA: I'm doing cross-platform things and in particular have c++ libraries that need to work everywhere, and have to write windows-only client applications to use those and other sdks.

nielsm
Jun 1, 2009



I've personally found Microsoft's own online documentation (MSDN Library) decent, although I'm sure it's not something that works for everyone. I've never had any books on Windows programming.

Some general pointers:
- You are not getting around working with UTF-16 strings at some level, perhaps unless you never need to touch the filesystem or UI at all. Plan for re-implementing any file access to call Windows' native APIs, and they all want UTF-16 Unicode strings.
- Learn at least the basics of COM, you don't need to master it but at least learn the semantics of IUnknown and CoCreateInstance.
- Keep in mind that there isn't a true common C++ ABI on Windows, C++ libraries built with different compilers won't necessarily link. In particular, mixing Microsoft and GCC is risky.
- IPC and RPC will also be very different, if you need to do that consider whether you can rely on a 3rd party library to abstract it.
- Making native GUIs for Windows with C++ can be painful, doing it in .NET land is generally a much better idea. However integrating native C++ libraries with .NET will require either having a pure C interface for the C++ code, or exposing it as a COM interface, or using some sort of IPC and running the C++ component out of process, or porting the C++ library to compile for .NET. That's obviously decisions to make early.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Probably. Having toyed with 0MQ a little, I see I'm asking for a lot. In my head, I was hoping for an independent service that would route all the messages. So I did not want to force the testbench software to have to connect to a port that an experiment set up. I wanted both sides to reach out to a central service and get mated up there. Afterwards, I'm thinking of something RPC-like behavior, but the experiments don't really need to know they're doing RPC calls. They're just indicating they're about to do something, and sometimes letting themselves block on it. Wait for the next post where I further qualify that too, until I've realized just how big of a problem I'm walking into.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Rocko Bonaparte posted:

Probably. Having toyed with 0MQ a little, I see I'm asking for a lot. In my head, I was hoping for an independent service that would route all the messages. So I did not want to force the testbench software to have to connect to a port that an experiment set up. I wanted both sides to reach out to a central service and get mated up there. Afterwards, I'm thinking of something RPC-like behavior, but the experiments don't really need to know they're doing RPC calls. They're just indicating they're about to do something, and sometimes letting themselves block on it. Wait for the next post where I further qualify that too, until I've realized just how big of a problem I'm walking into.

Designing a distributed architecture is never a trivial task. While there's no right answer it's hard to really know where to get started without a more thorough description of your requirements. That said, RabbitMQ is great.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Rocko Bonaparte posted:

Probably. Having toyed with 0MQ a little, I see I'm asking for a lot. In my head, I was hoping for an independent service that would route all the messages. So I did not want to force the testbench software to have to connect to a port that an experiment set up. I wanted both sides to reach out to a central service and get mated up there. Afterwards, I'm thinking of something RPC-like behavior, but the experiments don't really need to know they're doing RPC calls. They're just indicating they're about to do something, and sometimes letting themselves block on it. Wait for the next post where I further qualify that too, until I've realized just how big of a problem I'm walking into.

RabbitMQ, the project whats docs I linked to, is an independent service that you can configure to route messages in different ways including pub/sub and RPC patterns. Your testbench software could just sit idly listening for messages (subscriber) from your experiment (publisher) and the Rabbit server would handle routing.

omeg
Sep 3, 2012

nielsm posted:

I've personally found Microsoft's own online documentation (MSDN Library) decent, although I'm sure it's not something that works for everyone. I've never had any books on Windows programming.

Some general pointers:
- You are not getting around working with UTF-16 strings at some level, perhaps unless you never need to touch the filesystem or UI at all. Plan for re-implementing any file access to call Windows' native APIs, and they all want UTF-16 Unicode strings.
- Learn at least the basics of COM, you don't need to master it but at least learn the semantics of IUnknown and CoCreateInstance.
- Keep in mind that there isn't a true common C++ ABI on Windows, C++ libraries built with different compilers won't necessarily link. In particular, mixing Microsoft and GCC is risky.
- IPC and RPC will also be very different, if you need to do that consider whether you can rely on a 3rd party library to abstract it.
- Making native GUIs for Windows with C++ can be painful, doing it in .NET land is generally a much better idea. However integrating native C++ libraries with .NET will require either having a pure C interface for the C++ code, or exposing it as a COM interface, or using some sort of IPC and running the C++ component out of process, or porting the C++ library to compile for .NET. That's obviously decisions to make early.

If you want to know how stuff works behind the scenes, read (or skim) the Windows Internals book, it's pretty great.

hooah
Feb 6, 2006
WTF?
Does the linear complexity of DFS/BFS depend on nodes being marked as visited? If it does, does the complexity change to |V|*|E| or something quadratic?

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
If the nodes aren't marked as visited then they will never finish.

hooah
Feb 6, 2006
WTF?
Well, if you know the nodes ahead of time and put them into a queue you can avoid that.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm not quite sure what you mean by that. Which nodes are being put into the queue? In what order are they being put in? How are you using the queue?

hooah
Feb 6, 2006
WTF?
I'm trying to figure out if students' algorithms for 2-coloring a graph are linear time. Most of them do something like BFS or DFS, but most don't mark nodes as visited. Here's an example:
pre:
Q <- V // Put all vertices in a queue
x = Q.pop_back
while(!Q.empty)
    for each vertex y in x.adjacencylist
        if x.color == y.color
            return false
    x <- Q.pop_back

return true

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
That runs in O(V+E) time, but it doesn't color the graph. It merely verifies that it is colored.

Dr. Stab fucked around with this message at 17:11 on Apr 25, 2015

hooah
Feb 6, 2006
WTF?
Right, I was just unsure of the running time. Thanks.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm just a little confused because that's not BFS or DFS. If they needed to actually do one of those to generate a 2-coloring, you couldn't just visit the nodes in an arbitrary order.

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?

Dr. Stab posted:

I'm just a little confused because that's not BFS or DFS. If they needed to actually do one of those to generate a 2-coloring, you couldn't just visit the nodes in an arbitrary order.

:shrug: I'm just the grader.

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