Abstract Monte Carlo methods have extensively been used and studied in the area of stochastic programming. Their convergence properties typically consider global minimizers or first-order critical points of the sample average approximation (SAA) problems and minimizers of the true problem, and show that the former converge to the latter for increasing sample size. However, the assumption of global minimization essentially restricts the scope of these results to convex problems. We review and extend these results in two directions: we allow for local SAA minimizers of possibly nonconvex problems and prove, under suitable conditions, almost sure convergence of local second-order solutions of the SAA problem to second-order critical points of the true problem. We also apply this new theory to the estimation of mixed logit models for discrete choice analysis. New useful convergence properties are derived in this context, both for the constrained and unconstrained cases, and associated estimates of the simulation bias and variance are proposed.
Interesting programming ideas, solutions, and logic that I have used to solve problems or have come across throughout my career.
About Me
- William Andrus
- Northglenn, Colorado, United States
- I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).
Monday, July 10, 2006
Convergence theory for nonconvex stochastic programming with an application to mixed logit
http://www.springerlink.com/(gy1xnqenspq0bc55yyftgd55)/app/home/contribution.asp?referrer=parent&backto=issue,1,18;journal,2,146;linkingpublicationresults,1:103081,1
Wednesday, July 05, 2006
On change event in ASP.Net
In ASP.Net the ontextchanged event doesn't get called until a postback, the problem we had was to ask the user before leaving the page, if they would like to save any of their changes that were made, and to enable the submit button if there were changes. We had to go to javascript, again, for this answer.
The first function: saveChanges() is called when ever the user tries to change the current page or close the browser. It just asks if they user wants to leave without saving.
The second function is called when ever a textbox, or other asp/html control has changed. This basically just enables the submit button.
So, within the page we might have a ASP.Net control like this:
Now, you would end up getting a warning in ASP.Net since it doesn't recognize the onchange event, since this is actually a javascript event. The trick here is when the page is render this is how it would look in the html:
<script language="javascript" type="text/javascript">
window.onbeforeunload = saveChanges;
function saveChanges()
{
var changes = document.getElementById("<%=this.ButtonSubmit.ClientID%>").disabled;
if(!changes)
{
event.returnValue = 'Changes were not saved. Click Cancel to go back and submit changes, or click OK to continue.';
}
}
function enableSubmit()
{
document.getElementById("<%=this.ButtonSubmit.ClientID%>").disabled = false;
}
</script>
The first function: saveChanges() is called when ever the user tries to change the current page or close the browser. It just asks if they user wants to leave without saving.
The second function is called when ever a textbox, or other asp/html control has changed. This basically just enables the submit button.
So, within the page we might have a ASP.Net control like this:
<asp:textbox id="TextBox1" runat="server" onchange="enableSubmit()" width="49px"><asp:textbox>
Now, you would end up getting a warning in ASP.Net since it doesn't recognize the onchange event, since this is actually a javascript event. The trick here is when the page is render this is how it would look in the html:
<input id="ctl00_ContentPlaceHolder1_TextBox1" style="WIDTH: 49px" onchange="enableSubmit()" name="ctl00$ContentPlaceHolder1$TextBoxNotes">
Monday, June 26, 2006
Riddle: CRIMINAL CUPBEARERS
Source: http://www.ocf.berkeley.edu/~wwu/riddles/hard.shtml
First thing I noticed was that 2^10 is approx 1000 and saw that this dealt with some sort of binary solution. I then broke the question down into a smaller one. Dealing with 8 bottles of wine and 3 prisioners, assuming that the 2^10 has something to do with the solution.
So, I came up with this basic solution:
Bottle 1: Prisoner 1 drinks
Bottle 2: Prisoner 2 drinks
Bottle 3: Prisoner 3 drinks
Bottle 4: Prisoner 1 & 2 drinks
Bottle 5: Prisoner 1 & 3 drinks
Bottle 6: Prisoner 2 & 3 drinks
Bottle 7: Prisoner 1 & 2 & 3 drinks
Bottle 8: No one drinks.
So for example if prisoner 1 & 3 dies, then you know it must be bottle 5 that was poisoned.
I guess this could be looked at as some type of Venn diagram, and/or combinatorics. I don't know if this solution would work for 1000 bottles and 10 prisoners.
An evil king has 1000 bottles of wine. A neighboring queen plots to kill the bad king, and sends a servant to poison the wine. The king's guards catch the servant after he has only poisoned one bottle. The guards don't know which bottle was poisoned, but they do know that the poison is so potent that even if it was diluted 1,000,000 times, it would still be fatal. Furthermore, the effects of the poison take one month to surface. The king decides he will get some of his prisoners in his vast dungeons to drink the wine. Rather than using 1000 prisoners each assigned to a particular bottle, this king knows that he needs to murder no more than 10 prisoners to figure out what bottle is poisoned, and will still be able to drink the rest of the wine in 5 weeks time. How does he pull this off?
First thing I noticed was that 2^10 is approx 1000 and saw that this dealt with some sort of binary solution. I then broke the question down into a smaller one. Dealing with 8 bottles of wine and 3 prisioners, assuming that the 2^10 has something to do with the solution.
So, I came up with this basic solution:
Bottle 1: Prisoner 1 drinks
Bottle 2: Prisoner 2 drinks
Bottle 3: Prisoner 3 drinks
Bottle 4: Prisoner 1 & 2 drinks
Bottle 5: Prisoner 1 & 3 drinks
Bottle 6: Prisoner 2 & 3 drinks
Bottle 7: Prisoner 1 & 2 & 3 drinks
Bottle 8: No one drinks.
So for example if prisoner 1 & 3 dies, then you know it must be bottle 5 that was poisoned.
I guess this could be looked at as some type of Venn diagram, and/or combinatorics. I don't know if this solution would work for 1000 bottles and 10 prisoners.
Wednesday, June 21, 2006
How to redirect a page, the right way.
Good information to keep in mind for updating websites, using the 301.
http://www.stevenhargrove.com/redirect-web-pages/
Since, I'm developing mostly in ASP.Net, here is his sample code on how to use it.
http://www.stevenhargrove.com/redirect-web-pages/
Since, I'm developing mostly in ASP.Net, here is his sample code on how to use it.
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com/");
}
</script>
Algorithms
Here is a good source of Algorithms that are most commonly used in computer science. http://www.cse.ucsd.edu/~dasgupta/mcgrawhill/
I could probably add a couple, but I haven't look through the whole thing. I believe he is making this a book, but I believe their is already an algorithm book out there. Anyway, check it out, looks like a good find.
I could probably add a couple, but I haven't look through the whole thing. I believe he is making this a book, but I believe their is already an algorithm book out there. Anyway, check it out, looks like a good find.
Friday, June 09, 2006
Way to execute a file through an ASP.Net page.
Very simple and quick:
System.Diagnostics.Process.Start(LocationOfString);
System.Diagnostics.Process.Start(LocationOfString);
Friday, June 02, 2006
Multiple Control Validator
Ok, so I have to come up with a validation control that would validate two textboxes to see if either one has been populated. The custom validator, unfortuntly, only validates if something has been entered into one of the textboxes. To get around this I set up two private boolean values to represent if text has been entered or not.
private bool TxtBox1 = false;
private bool TxtBox2 = false;
I then have my two custom validator functions, which are similar, except for the name of the second validator and it's TxtBox2:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value == "")
{
TxtBox1 = false;
}
else
{
TxtBox1 = true;
}
args.IsValid = getValidation();
}
So, I just check if there was a value entered and set my private variables.
I then call a function to assign the validation.
private bool getValidation()
{
if (TxtBox1 TxtBox2)
{
return true;
}
else
{
return false;
}
}
Now to deal with the textboxes being both empt
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
this.Page.Validate();
if (TxtBox1 == false && TxtBox2 == false)
{
this.CustomValidator1.IsValid = false;
this.CustomValidator2.IsValid = false;
}
}
First validate the other controls, then validate our custom controls to see if both were left blank.
If so, then set both validators to false.
This is what I came up with so far, I might find a way to improve the summary, so that it would only give one line as the error instead of 2.
private bool TxtBox1 = false;
private bool TxtBox2 = false;
I then have my two custom validator functions, which are similar, except for the name of the second validator and it's TxtBox2:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value == "")
{
TxtBox1 = false;
}
else
{
TxtBox1 = true;
}
args.IsValid = getValidation();
}
So, I just check if there was a value entered and set my private variables.
I then call a function to assign the validation.
private bool getValidation()
{
if (TxtBox1 TxtBox2)
{
return true;
}
else
{
return false;
}
}
Now to deal with the textboxes being both empt
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
this.Page.Validate();
if (TxtBox1 == false && TxtBox2 == false)
{
this.CustomValidator1.IsValid = false;
this.CustomValidator2.IsValid = false;
}
}
First validate the other controls, then validate our custom controls to see if both were left blank.
If so, then set both validators to false.
This is what I came up with so far, I might find a way to improve the summary, so that it would only give one line as the error instead of 2.
Sunday, May 21, 2006
We want no postbacks
Well last week I had to quickly redevelop the web forms I developed to implement no postbacks. The forms we are developing has several fields and to do a post back on each one would slow the webpages down. So the solution was simple enough of switching out asp image button with a old style html input button. Now we can open a new window without postback and send back information into a textbox field with out any slow downs.
P.S. I have a complaint about about browsers and W3C, to center a page you have to use the attribute "style" with the left and right width to auto. The thing is that this doesn't work in the browsers (IE and Firefox). So while in VS 2005 I made a div tag with the attribute 'align' sent to center, but this of course gives a warning that this technique is out dated. WTF?!?!?!?!?!?!?!?!?!
P.S. I have a complaint about about browsers and W3C, to center a page you have to use the attribute "style" with the left and right width to auto. The thing is that this doesn't work in the browsers (IE and Firefox). So while in VS 2005 I made a div tag with the attribute 'align' sent to center, but this of course gives a warning that this technique is out dated. WTF?!?!?!?!?!?!?!?!?!
Saturday, May 13, 2006
Web Controls and Pop Up Windows with ASP.Net 2.0
One of the first web controls that we developed with good reusability is a web control that pops up another window. This doesn't seem much, but does give more posibilites of what can then be done on the newly open window.
Well, to have a pop up window, we developed a image button, which can be used and is more user friendly. We also wanted to make it more possible to change the size of the pop up window.
private System.Web.UI.WebControls.ImageButton _imageBtn; //Button with image used to call pop-up page
private System.String _popUpLoc; //Location of the popup page
private System.Web.UI.WebControls.Unit _popUpPageWidth; //Width of the pop up page
private System.Web.UI.WebControls.Unit _popUpPageHeight; //Height of the pop up page
Next are the properties so we can change values during the design view. Most of which are obvious, so here is an example of one:
[Bindable(true)]//used for binding
[Category("Pop Up Window")] //in properties section "Pop Up Window"
[Description("The URL of the pop-up webpage")]//description of PagePopUp
[DefaultValue("")]//default value
[Localizable(true)]//allow multi-language
public virtual System.String PopUpURL
{
get
{
return this._popUpLoc; //returns a string representing the location of the image
}
set
{
this._popUpLoc = value; //set the string value for the location of the image button
}
}
etc... for the other properties you might want to set. Use EnsureChildControls(); for controls that are used on the page.
Next override the CreateChildControls:
protected override void CreateChildControls()
{
Controls.Clear(); //clear the controls before adding them
this._imageBtn = new System.Web.UI.WebControls.ImageButton();//declare image button with image on it
this._imageBtn.ID = "CalendarBtn";//set the id of the image button
Controls.Add(this._imageBtn);//add the image button to the child control collection
}
In the render control is where we add an attribute to the image button.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
AddAttributesToRender(writer); //add HTML that needs to be render
/*
* Calls javascript to open a new window and send in the text box id
*
* this.PopUpURL is the page to pop open
* this.Page.Form.ClientID represents the page's form id eg:
* this.ClientID represents the web controls's ID eg:
* the height and width variables are used to set the dimensions of the browser
* the status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no are used to remove usless items and fixate the window size
*
* Note: since during the page initialization the controls are developed before the page
* we had to place the _imageBtn.Attributes.Add(...) into the render method
* to prevent NullException error.
*
*/
_imageBtn.Attributes.Add("onclick", "window.open('" + this._popUpLoc
+ "?field=" + this.Page.Form.ClientID + "." + this.ClientID
+ "',null,'height=" + this._popUpPageHeight + ", width="
+ this._popUpPageWidth + ",status= no, resizable= no, scrollbars=no, toolbar=no, location=no, menubar=no ');");
this._imageBtn.RenderControl(writer);//render the image button
}
Well, to have a pop up window, we developed a image button, which can be used and is more user friendly. We also wanted to make it more possible to change the size of the pop up window.
private System.Web.UI.WebControls.ImageButton _imageBtn; //Button with image used to call pop-up page
private System.String _popUpLoc; //Location of the popup page
private System.Web.UI.WebControls.Unit _popUpPageWidth; //Width of the pop up page
private System.Web.UI.WebControls.Unit _popUpPageHeight; //Height of the pop up page
Next are the properties so we can change values during the design view. Most of which are obvious, so here is an example of one:
[Bindable(true)]//used for binding
[Category("Pop Up Window")] //in properties section "Pop Up Window"
[Description("The URL of the pop-up webpage")]//description of PagePopUp
[DefaultValue("")]//default value
[Localizable(true)]//allow multi-language
public virtual System.String PopUpURL
{
get
{
return this._popUpLoc; //returns a string representing the location of the image
}
set
{
this._popUpLoc = value; //set the string value for the location of the image button
}
}
etc... for the other properties you might want to set. Use EnsureChildControls(); for controls that are used on the page.
Next override the CreateChildControls:
protected override void CreateChildControls()
{
Controls.Clear(); //clear the controls before adding them
this._imageBtn = new System.Web.UI.WebControls.ImageButton();//declare image button with image on it
this._imageBtn.ID = "CalendarBtn";//set the id of the image button
Controls.Add(this._imageBtn);//add the image button to the child control collection
}
In the render control is where we add an attribute to the image button.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
AddAttributesToRender(writer); //add HTML that needs to be render
/*
* Calls javascript to open a new window and send in the text box id
*
* this.PopUpURL is the page to pop open
* this.Page.Form.ClientID represents the page's form id eg:
* this.ClientID represents the web controls's ID eg:
* the height and width variables are used to set the dimensions of the browser
* the status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no are used to remove usless items and fixate the window size
*
* Note: since during the page initialization the controls are developed before the page
* we had to place the _imageBtn.Attributes.Add(...) into the render method
* to prevent NullException error.
*
*/
_imageBtn.Attributes.Add("onclick", "window.open('" + this._popUpLoc
+ "?field=" + this.Page.Form.ClientID + "." + this.ClientID
+ "',null,'height=" + this._popUpPageHeight + ", width="
+ this._popUpPageWidth + ",status= no, resizable= no, scrollbars=no, toolbar=no, location=no, menubar=no ');");
this._imageBtn.RenderControl(writer);//render the image button
}
Tuesday, May 09, 2006
How To: Run Web Control next to an application during development
So here at work, we are trying to get some web controls to work with pop-up windows. Here is a nice easy way to set up your test envirnoment.
Create a new website for testing. Eg. WebControlTester.
within the Solution Explorer place your web control into a new folder App_Code
then add a web.config file to the Solution Explorer.
Within the web.config file add:
<pages>
<controls>
<add namespace="Your.Namespace.In.WebControl" tagprefix="SomeTagPrefix">
</controls>
</pages>
Now you can edit your web control, build it and then switch to the web site and run it.
<^_^>
Create a new website for testing. Eg. WebControlTester.
within the Solution Explorer place your web control into a new folder App_Code
then add a web.config file to the Solution Explorer.
Within the web.config file add:
<pages>
<controls>
<add namespace="Your.Namespace.In.WebControl" tagprefix="SomeTagPrefix">
</controls>
</pages>
Now you can edit your web control, build it and then switch to the web site and run it.
<^_^>
Subscribe to:
Posts (Atom)