Custom Weighted Cross Entropy loss in KerasHow to log Keras loss output to a fileCustom loss function in KerasTensorFlow: Implementing a class-wise weighted cross entropy loss?Weighted mse custom loss function in kerasSoftmax Cross Entropy with Weights over Samples in TensorflowKeras custom loss function with different weights per exampleCustom Keras Loss Function with Internal PredictionCustom Loss function Keras combining Cross entropy loss and mae loss for Ordinal ClassificationCustom binary cross-entropy loss with weight-map using Keras

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Quoting Keynes in a lecture

Why is so much work done on numerical verification of the Riemann Hypothesis?

Why do ¬, ∀ and ∃ have the same precedence?

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

How could a planet have erratic days?

How can ping know if my host is down

Is this part of the description of the Archfey warlock's Misty Escape feature redundant?

Is there a nicer/politer/more positive alternative for "negates"?

What is the English pronunciation of "pain au chocolat"?

What kind of floor tile is this?

"It doesn't matter" or "it won't matter"?

Review your own paper in Mathematics

What does Apple's new App Store requirement mean

Has any country ever had 2 former presidents in jail simultaneously?

Why should universal income be universal?

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

Is there a RAID 0 Equivalent for RAM?

Does Doodling or Improvising on the Piano Have Any Benefits?

Doesn't the system of the Supreme Court oppose justice?

"Oh no!" in Latin

Does "he squandered his car on drink" sound natural?



Custom Weighted Cross Entropy loss in Keras


How to log Keras loss output to a fileCustom loss function in KerasTensorFlow: Implementing a class-wise weighted cross entropy loss?Weighted mse custom loss function in kerasSoftmax Cross Entropy with Weights over Samples in TensorflowKeras custom loss function with different weights per exampleCustom Keras Loss Function with Internal PredictionCustom Loss function Keras combining Cross entropy loss and mae loss for Ordinal ClassificationCustom binary cross-entropy loss with weight-map using Keras













0















Ok, so I have a neural network that classifies fire size into 3 groups, 0-1, 1 - 100, and over 100 acres. I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)










share|improve this question


























    0















    Ok, so I have a neural network that classifies fire size into 3 groups, 0-1, 1 - 100, and over 100 acres. I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)










    share|improve this question
























      0












      0








      0








      Ok, so I have a neural network that classifies fire size into 3 groups, 0-1, 1 - 100, and over 100 acres. I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)










      share|improve this question














      Ok, so I have a neural network that classifies fire size into 3 groups, 0-1, 1 - 100, and over 100 acres. I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)







      tensorflow machine-learning keras neural-network loss-function






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 5:04









      Dylan WichmanDylan Wichman

      31




      31






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)



          double of what?.



          A)Is it the double the loss value when the classifier guesses correctly,



          B)or double the loss value when the classifier is off by 1.



          C)Can we relax this 'double' constraint, and can we assume that any suitable higher power would suffice?



          Let us assume A).



          Let f(x) denotes the probability that your input variable belong to a particular class. Note that, in f(x), x is the absolute value of the difference in categorical value.



          Then we see that f(0)=0.5 is a solution for assumption A. This means that f(1)=0.25 and f(2)=0.25. Btw, the fact that f(1)==f(2) doesn't look natural.



          Assume that your classifier calculates a function f(x), and uses it as follows.



          def classifier_output(firesize):
          if (firesize >=0 and firesize < 1.0):
          return [f(0), f(1), f(2)]
          elif (firesize >= 1.0 and firesize < 100.0):
          return [f(1), f(0), f(1)]
          else :
          assert(firesize > 100.0)
          return (f(2), f(1), f(0)]


          The constraints are



          C1)



          f(x) >=0


          C2)



          the components of your output vector should always sum to 1.0
          ie. sum of all three components of the return value should always be 1.


          C3)



          When the true class and predicted class differ by 2, the 1-hot encoding loss 
          will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).


          ie:



          log(f(2))=2*log(f(0))


          This translates to



          f(2) = f(0)*f(0)


          Let us put z=f(0). Now f(2)=z*z. We don't know f(1). Let us assume, f(1)=y.



          From the constraint C2,
          We have the following equations,



          z+ z*z + y=1
          z + 2*y=1


          A solution to the above is z=0.5, y=0.25



          If you assume B), you wont be able to find such a function.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036428%2fcustom-weighted-cross-entropy-loss-in-keras%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)



            double of what?.



            A)Is it the double the loss value when the classifier guesses correctly,



            B)or double the loss value when the classifier is off by 1.



            C)Can we relax this 'double' constraint, and can we assume that any suitable higher power would suffice?



            Let us assume A).



            Let f(x) denotes the probability that your input variable belong to a particular class. Note that, in f(x), x is the absolute value of the difference in categorical value.



            Then we see that f(0)=0.5 is a solution for assumption A. This means that f(1)=0.25 and f(2)=0.25. Btw, the fact that f(1)==f(2) doesn't look natural.



            Assume that your classifier calculates a function f(x), and uses it as follows.



            def classifier_output(firesize):
            if (firesize >=0 and firesize < 1.0):
            return [f(0), f(1), f(2)]
            elif (firesize >= 1.0 and firesize < 100.0):
            return [f(1), f(0), f(1)]
            else :
            assert(firesize > 100.0)
            return (f(2), f(1), f(0)]


            The constraints are



            C1)



            f(x) >=0


            C2)



            the components of your output vector should always sum to 1.0
            ie. sum of all three components of the return value should always be 1.


            C3)



            When the true class and predicted class differ by 2, the 1-hot encoding loss 
            will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).


            ie:



            log(f(2))=2*log(f(0))


            This translates to



            f(2) = f(0)*f(0)


            Let us put z=f(0). Now f(2)=z*z. We don't know f(1). Let us assume, f(1)=y.



            From the constraint C2,
            We have the following equations,



            z+ z*z + y=1
            z + 2*y=1


            A solution to the above is z=0.5, y=0.25



            If you assume B), you wont be able to find such a function.






            share|improve this answer





























              0














              I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)



              double of what?.



              A)Is it the double the loss value when the classifier guesses correctly,



              B)or double the loss value when the classifier is off by 1.



              C)Can we relax this 'double' constraint, and can we assume that any suitable higher power would suffice?



              Let us assume A).



              Let f(x) denotes the probability that your input variable belong to a particular class. Note that, in f(x), x is the absolute value of the difference in categorical value.



              Then we see that f(0)=0.5 is a solution for assumption A. This means that f(1)=0.25 and f(2)=0.25. Btw, the fact that f(1)==f(2) doesn't look natural.



              Assume that your classifier calculates a function f(x), and uses it as follows.



              def classifier_output(firesize):
              if (firesize >=0 and firesize < 1.0):
              return [f(0), f(1), f(2)]
              elif (firesize >= 1.0 and firesize < 100.0):
              return [f(1), f(0), f(1)]
              else :
              assert(firesize > 100.0)
              return (f(2), f(1), f(0)]


              The constraints are



              C1)



              f(x) >=0


              C2)



              the components of your output vector should always sum to 1.0
              ie. sum of all three components of the return value should always be 1.


              C3)



              When the true class and predicted class differ by 2, the 1-hot encoding loss 
              will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).


              ie:



              log(f(2))=2*log(f(0))


              This translates to



              f(2) = f(0)*f(0)


              Let us put z=f(0). Now f(2)=z*z. We don't know f(1). Let us assume, f(1)=y.



              From the constraint C2,
              We have the following equations,



              z+ z*z + y=1
              z + 2*y=1


              A solution to the above is z=0.5, y=0.25



              If you assume B), you wont be able to find such a function.






              share|improve this answer



























                0












                0








                0







                I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)



                double of what?.



                A)Is it the double the loss value when the classifier guesses correctly,



                B)or double the loss value when the classifier is off by 1.



                C)Can we relax this 'double' constraint, and can we assume that any suitable higher power would suffice?



                Let us assume A).



                Let f(x) denotes the probability that your input variable belong to a particular class. Note that, in f(x), x is the absolute value of the difference in categorical value.



                Then we see that f(0)=0.5 is a solution for assumption A. This means that f(1)=0.25 and f(2)=0.25. Btw, the fact that f(1)==f(2) doesn't look natural.



                Assume that your classifier calculates a function f(x), and uses it as follows.



                def classifier_output(firesize):
                if (firesize >=0 and firesize < 1.0):
                return [f(0), f(1), f(2)]
                elif (firesize >= 1.0 and firesize < 100.0):
                return [f(1), f(0), f(1)]
                else :
                assert(firesize > 100.0)
                return (f(2), f(1), f(0)]


                The constraints are



                C1)



                f(x) >=0


                C2)



                the components of your output vector should always sum to 1.0
                ie. sum of all three components of the return value should always be 1.


                C3)



                When the true class and predicted class differ by 2, the 1-hot encoding loss 
                will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).


                ie:



                log(f(2))=2*log(f(0))


                This translates to



                f(2) = f(0)*f(0)


                Let us put z=f(0). Now f(2)=z*z. We don't know f(1). Let us assume, f(1)=y.



                From the constraint C2,
                We have the following equations,



                z+ z*z + y=1
                z + 2*y=1


                A solution to the above is z=0.5, y=0.25



                If you assume B), you wont be able to find such a function.






                share|improve this answer















                I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)



                double of what?.



                A)Is it the double the loss value when the classifier guesses correctly,



                B)or double the loss value when the classifier is off by 1.



                C)Can we relax this 'double' constraint, and can we assume that any suitable higher power would suffice?



                Let us assume A).



                Let f(x) denotes the probability that your input variable belong to a particular class. Note that, in f(x), x is the absolute value of the difference in categorical value.



                Then we see that f(0)=0.5 is a solution for assumption A. This means that f(1)=0.25 and f(2)=0.25. Btw, the fact that f(1)==f(2) doesn't look natural.



                Assume that your classifier calculates a function f(x), and uses it as follows.



                def classifier_output(firesize):
                if (firesize >=0 and firesize < 1.0):
                return [f(0), f(1), f(2)]
                elif (firesize >= 1.0 and firesize < 100.0):
                return [f(1), f(0), f(1)]
                else :
                assert(firesize > 100.0)
                return (f(2), f(1), f(0)]


                The constraints are



                C1)



                f(x) >=0


                C2)



                the components of your output vector should always sum to 1.0
                ie. sum of all three components of the return value should always be 1.


                C3)



                When the true class and predicted class differ by 2, the 1-hot encoding loss 
                will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).


                ie:



                log(f(2))=2*log(f(0))


                This translates to



                f(2) = f(0)*f(0)


                Let us put z=f(0). Now f(2)=z*z. We don't know f(1). Let us assume, f(1)=y.



                From the constraint C2,
                We have the following equations,



                z+ z*z + y=1
                z + 2*y=1


                A solution to the above is z=0.5, y=0.25



                If you assume B), you wont be able to find such a function.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 16:43

























                answered Mar 7 at 16:11









                koshy georgekoshy george

                453517




                453517





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036428%2fcustom-weighted-cross-entropy-loss-in-keras%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved