Speech recognition with Neural Networks

Hello everybody,

today I want to share how to deal with the Speech Recognition with Neural Networks.

So, the speech recognition task has following stages:

  1. Pre-processing: convert the sound wave into a vector of acoustic coefficients. Extract a new vector about every 10 milliseconds
  2. Acoustic model: Use a few adjacent vectors of acoustic coefficients to place bets on which par of which phoeneme is being spoken.
  3. Decoding: Find the sequence of bets that does the best job of fitting the acoustic data and also fitting a model of the kinds of thinks people say.

Some simple models of neurons

Hello everybody,

today I want to describe some simple models of neurons. Bet before I'll continue, just few words why to worry at all about simplification of neurons. The answer on question why is simple: simplification helps to understand bigger picture ( well not always ) and also allows to apply mathematics and make analogies to other familiar systems.

Now let's see models of "Idealized" neurons:

1. Linear neurons.  Output is sum of bias plus multiplication of multiplication of inputs with weights.

Here is how it's chart look like:

2. Binary threshold neurons. It has following stages of calculation:

  • Compute a weighted sum of the inputs (1)
  • Send out fixed size spike of activity if the (1) exceeds a threshold

Below goes graphical representation with case if threshold = 1

thre are tow equal ways to write equation for binary threshold neuron:

3. Rectified Linear Neurons

it has features of linear and non-linear neurons. Sometime such model is useful.

4. Sigmoid neurons. That one uses some kind of function ( typically logistic ). Another important detail kind of function should be easily derivative.

Below goes example of logistic neuron:

5. Stochastic binary neurons. For me it is puzzling. The use the same equation as logistic but they will output zero or one. And you never know for sure, what it will be. You just know, that the higher is output, the more chances of one, the lower is output, the more chances of zero.

Send post/get/delete to Jira

Hello everybody,

today I want to share, how I make rest requests to jira. Here I found class RequestsExtensions. 

It works fine for cases if authentication and authoritation is not needed. Bug for cases if authentication and authoritation in jira is needed that class doesn't work properly. In order to fix it I've added function which imitates log in.

Below goes code which I use:

public static class WebRequester
    {
        /// <summary>
        /// Sending POST request.
        /// </summary>
        /// <param name="url">Request Url.</param>
        /// <param name="data">Data for request.</param>
        /// <param name="userName">user name for log in</param>
        /// <param name="password">password for log in</param>
        /// <returns>Response body.</returns>
        public static string HttpPost(string url, string data, string userName = "", string password = "", int timeout = 100000)
        {
            
            string Out = String.Empty;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            try
            {
                req.ContentType = "application/json";
                req.Method = "POST";
                req.ProtocolVersion = HttpVersion.Version11;
                req.Accept = "*/*";

                AddAuthentication(userName, password, req);
               
                req.Timeout = timeout;
                //req.ContentType = "application/x-www-form-urlencoded";
                byte[] sentData = Encoding.UTF8.GetBytes(data);
                req.ContentLength = sentData.Length;
                using (System.IO.Stream sendStream = req.GetRequestStream())
                {
                    sendStream.Write(sentData, 0, sentData.Length);
                    sendStream.Flush();
                    sendStream.Close();
                }
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                System.IO.Stream ReceiveStream = res.GetResponseStream();
                using (System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8))
                {
                    Char[] read = new Char[256];
                    int count = sr.Read(read, 0, 256);

                    while (count > 0)
                    {
                        String str = new String(read, 0, count);
                        Out += str;
                        count = sr.Read(read, 0, 256);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message);
            }
            catch (WebException ex)
            {
                Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message);
            }

            return Out;
        }

        /// <summary>
        /// Sending GET request.
        /// </summary>
        /// <param name="url">Request Url.</param>
        /// <param name="data">Data for request.</param>
        /// <param name="userName">user name for log in</param>
        /// <param name="password">password for log in</param>
        /// <returns>Response body.</returns>
        public static string HttpGet(string url, string data, string userName, string password)
        {
            string Out = String.Empty;
            Uri uri = new Uri(url);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + (string.IsNullOrEmpty(data) ? "" : "?" + data));
            req.ContentType = "application/json";
            req.Method = "GET";

            AddAuthentication(userName, password, req);
            try
            {
                System.Net.WebResponse resp = req.GetResponse();
                using (System.IO.Stream stream = resp.GetResponseStream())
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
                    {
                        Out = sr.ReadToEnd();
                        sr.Close();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message);
            }
            catch (WebException ex)
            {
                Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message);
            }

            return Out;
        }

        private static void AddAuthentication(string userName, string password, HttpWebRequest req)
        {
            if (userName != null && password != null)
            {
                string base64Credentials = GetEncodedCredentials(userName, password);
                req.Headers.Add("Authorization", "Basic " + base64Credentials);
            }
        }

        /// <summary>
        /// Sending Delete request.
        /// </summary>
        /// <param name="url">Request Url.</param>
        /// <param name="data">Data for delete.</param>
        /// <param name="userName">user name for log in</param>
        /// <param name="password">password for log in</param>
        /// <returns>Response body.</returns>
        public static string HttpDelete(string url, string data, string userName, string password)
        {
            string Out = String.Empty;
            Uri uri = new Uri(url);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + (string.IsNullOrEmpty(data) ? "" : "?" + data));
            req.ContentType = "application/json";
            req.Method = "DELETE";

            AddAuthentication(userName, password, req);

            try
            {
                System.Net.WebResponse resp = req.GetResponse();
                using (System.IO.Stream stream = resp.GetResponseStream())
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
                    {
                        Out = sr.ReadToEnd();
                        sr.Close();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message);
            }
            catch (WebException ex)
            {
                Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message);
            }

            return Out;
        }

        private static string GetEncodedCredentials(string userName, string password)
        {
            string mergedCredentials = string.Format("{0}:{1}", userName, password);
            byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
            return Convert.ToBase64String(byteCredentials);
        }
    }

Send curl request to Jira from command prompt

Hello everybody,

Few days ago I had a task to send delete link request to jira. For this pupose I found curl utility, and here is how delete request can be submitted from command prompt:

curl --user jiraUserName:jiraUserPassword  -X DELETE -H "Content-Type: application/json" http://yourJiraInstance/rest/tempo-accounts/1/link/267.

Despite fact that jira claims that in response we will get true or false, in reality I received {"id":267,"scopeType":"PROJECT","scope":10452,"accountId":5,"key":"QASSURANCE","name":"Quality Assurance","linkType":"MANUAL"}. I have no idea why response was like this, but the fact is fact. Response is another then simply true/false.

How to provide data for the grid in Acumatica without persiting it to db.

Hello everybody,

today I discovered for myself new member of Acumcatica. Welcome PXProcessing with it's relatives.

• PXProcessing: allows you to work with data records for processing without filtering. You can use the Where<> and OrderBy<>clauses in this data view type.

• PXProcessingJoin: allows you to work with data records for processing without filtering. You can also use Join<>clauses in this data view type.

• PXFilteredProcessing: allows you to work with data records for processing with filtering. This data type takes two DACs as type parameters, where the second DAC specifies the filter DAC. You can use the Where<>and OrderBy<>clauses in this data view type.

• PXFilteredProcessingJoin: allows you to work with data records for processing with filter. This data type takes two DACs as type parameters, where the second DAC specifies the filter DAC. You can also use Join<>clauses in this data view type.

As you can see the simplest is PXProcessing with which you can work with one DAC.  Other have features as Join, two classes, OrderBy, etc. But if you wish, you can substitute them completely with something that you consider as needed.

Updating Acumatica to newer version of Acumatica

Hello everybody,

toda I want to share some small notice about what options do you have during updating of Acumatica.

So. Imagine you make update from version 4.2 to version 5.1 and suddenly you have this error message:

Text of error message says, that you have some problems at your db. And you have three options:

1. Abort

2. Retry

3. Ignore.

 

Initially when I made update I was very scared of that error message and as usually selected Abort, but prior to it copy/pasted error message. It's not very wrong idea, but to execute updater after each error message is little bit slover process. Then I put my attention at another button. Retry. I know it sounds funny, that after some numbers of updates, I noticed that button. But I really liked it. Retry button gives me option during Update to fix troubles in DB, and continue updating process without need of pressing abort, or ignore the problem. Another useful feature is to take into account inner messages, call stack and even script. Those features can help to solve some additional problems, or give more food for mind about which part of db may contain data, which you can't use.

Types of redirects in Acumatica

Hello everybody,

today I want to note about redirects. In Acumatica you can redirect user to another webpage. Acumatica provides option of redirecting to following scenarios:

  • To another page in Acumatica
  • To another report
  • To any destination url

Try to gues, how redirections are implemented? As exception. If you consider it as wrong approach, I can partially agree with you. But only partially, because redirecting to antoher page is really some kind of exceptional situation. 

Below goes code of redirecting to page PM302000 at some TaskID and some projectid selected, which will be opened in new window:

UsrPMTaskReplace taskRepl = JiraAccountTasks.Current;
ProjectTaskEntry graph = PXGraph.CreateInstance<ProjectTaskEntry>();
graph.Task.Current = Base.Task.Current;
graph.Task.Current.ProjectID = taskRepl.UsrProjectID;

if (graph.Task.Current != null)
 {
    throw new PXRedirectRequiredException(graph, true, "Project Tasks");
}

If to speak more about other kinds of redirects, here it goes full list:

  1. PXRedirectRequiredException. Goes inside of Acumatica to some screen, or opens new one in another window. By default user will stay in the same window.
  2. PXPopupRedirectException. Inside Acumatica will be opened pop-up window.
  3. PXReportRequiredException. Opens report in the same or new window.
  4. PXRedirectWithReportException. This one is really cool because it can open two pages: the specified report in a new window, and the specified application page in the same window.
  5. PXRedirectToUrlException. Specified external page will be opened in a new window. BTW, you can use this exception for opening inquiry page.

DependOnGrid in Acumatica or how to get currently selected record in grid

Hello everybody,

today I want to share one important note, for search of which I've spent for two hours. 

In grid I've added button in the following way:

<ActionBar ActionsText="True">
 <CustomItems>
    <px:PXToolBarButton>
            <AutoCallBack Command="RemovePMTask" Target="ds" >
            </AutoCallBack>
    </px:PXToolBarButton>
 </CustomItems>
</ActionBar>

Initially described it in the following way:

<px:PXDSCallbackCommand Name="RemovePMTask" Visible="False" 
            </px:PXDSCallbackCommand>


Then added code for button in graph, and noticed terrible behaviour. In my action I wasn't able to get currently selected record in grid. After wondering for two hours, I found that I need to add attribute DependOnGrid. After adding that attribute my code started to work well and get posibility to get currently selected record.

But  for getting current record it was nesessary to add DependOnGrid="grdJiraProjects"

<px:PXDSCallbackCommand Name="RemovePMTask" Visible="False" DependOnGrid="grdJiraProjects">
            </px:PXDSCallbackCommand>

How to add list values to drop down in Acumatica

Hello everybody,

today I want to make quick notice of how to make drop down values in Acumatica avalable. 

Let's imagine, that you need following drow down list:

In order to get this kind of list, you can use the following code:

public static class JiraAccountStatusEnum
{
      public const string Open = "O";
      public const string Closed = "C";
      public const string Archived = "A";
}

public class JiraAccountListAttribute : PXStringListAttribute
{
   public JiraAccountListAttribute() : base(
            new string[] {JiraAccountStatusEnum.Open, JiraAccountStatusEnum.Closed, 
JiraAccountStatusEnum.Archived}, new string[] {"Open", "Closed", "Archived"}) { } }

2. In your DAC member class write the following:

#region UsrStatus
public abstract class usrStatus : IBqlField
{
}

protected string _UsrStatus;
[PXUIField(DisplayName = "Status")]
[PXDBString(10)]
[JiraAccountList]
public virtual string UsrStatus
{
   get
      {
        return _UsrStatus;
      }
   set
      {
        _UsrStatus = value;
      }
}
#endregion

3. Finally in your aspx page use the following control:

<px:PXDropDown ID="pxddUsrStatus" runat="server" DataField="UsrStatus"></px:PXDropDown>

That's it what is needed. If you follow steps, mentioned in this notice, you'll get drop down, screenshot of which you've seen.

Machine learning certificate from coursera

Hello everybody,

I want to boast that I receved certificate from Standfor Univercity about my level of knowledge in Machine Learning.

Here is the link:

https://www.coursera.org/maestro/api/certificate/get_certificate?course_id=973756

and here is screenshot: